Exemplo n.º 1
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();
            }
        }
        private void ToolStripMenuItemSelectShippingService_Click(object sender, EventArgs e)
        {
            FrmSelectShippingService frmSelectShippingService = new FrmSelectShippingService();

            frmSelectShippingService.ShowDialog();

            KeyValuePair <string, string> shippingServicePair = frmSelectShippingService.SelectedShippingService;

            if (shippingServicePair.Key == null)
            {
                return;
            }

            string shippingServiceCode = shippingServicePair.Key;
            string shippingServiceDesc = shippingServicePair.Value;

            DataGridViewSelectedRowCollection selectedRows = this.dataGridViewAllOrders.SelectedRows;
            List <string> orderLineItemIds = new List <string>();

            foreach (DataGridViewRow row in selectedRows)
            {
                String orderLineItemId = row.Cells[OrderDgv_OrderLineItemIndex].Value.ToString();
                if (orderLineItemId == "")
                {
                    continue;
                }
                orderLineItemIds.Add(orderLineItemId);
                row.Cells[OrderDgv_ShippingServiceIndex].Value = shippingServiceDesc;
            }

            EbayTransactionDAL.UpdateTransactionsShippingService(orderLineItemIds, shippingServiceCode, shippingServiceDesc);
            MessageBox.Show("设置物流方式成功", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
Exemplo n.º 3
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);
        }
        private void buttonUploadTrackingNumber_Click(object sender, EventArgs e)
        {
            if (ebayTrans == null || account == null)
            {
                return;
            }

            string sellerName = ebayTrans.SellerName;

            if (null == sellerName)
            {
                return;
            }

            string shippingCarrier        = textBoxCarrier.Text.Trim();
            string shipmentTrackingNumber = textBoxTrackingNumber.Text.Trim();

            if (shippingCarrier == "" || shipmentTrackingNumber == "")
            {
                MessageBox.Show("输入错误!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            EbayTransactionBiz.UploadTrackingNumber(account, ebayTrans.ItemId, ebayTrans.EbayTransactionId,
                                                    shippingCarrier, shipmentTrackingNumber);
            MessageBox.Show("上传跟踪号成功!", "成功", MessageBoxButtons.OK, MessageBoxIcon.Information);

            EbayTransactionDAL.UpdateTransactionShippingTrackingNo(ebayTrans.TransactionId, shipmentTrackingNumber);
        }
Exemplo n.º 5
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;
        }
Exemplo n.º 6
0
        private void buttonAskBuyer_Click(object sender, EventArgs e)
        {
            DataTable dtTrans = EbayTransactionDAL.GetOneTransactionTable(EbayTransaction.TransactionId);

            if (dtTrans == null || dtTrans.Rows.Count == 0)
            {
                return;
            }

            DataTable orderTable = dtTrans.Clone();
            DataRow   newRow     = orderTable.NewRow();

            newRow.ItemArray = dtTrans.Rows[0].ItemArray;
            orderTable.Rows.Add(newRow);

            FrmSendMessage frm = new FrmSendMessage();

            frm.OrdersDataTable = orderTable;
            frm.StartPosition   = FormStartPosition.CenterScreen;
            frm.ShowDialog();

            if (frm.MessageSent)
            {
                LoadMsgData();
            }
        }
Exemplo n.º 7
0
        private void LoadPostSaleData()
        {
            PostSaleCount = EbayTransactionDAL.GetPendingOrdersCount(0);
            int postSalePageCnt = PostSaleCount / PostSalePageSize + 1;

            if (CurrentPostSalePage < 1)
            {
                CurrentPostSalePage = 1;
            }
            else if (CurrentPostSalePage > postSalePageCnt)
            {
                CurrentPostSalePage = postSalePageCnt;
            }

            this.buttonPostSaleFirstPage.Enabled = true;
            this.buttonPostSaleLastPage.Enabled  = true;
            this.buttonPostSalePrevPage.Enabled  = true;
            this.buttonPostSaleNextPage.Enabled  = true;

            if (CurrentPostSalePage == 1)
            {
                this.buttonPostSaleFirstPage.Enabled = false;
                this.buttonPostSalePrevPage.Enabled  = false;
            }
            if (CurrentPostSalePage == postSalePageCnt)
            {
                this.buttonPostSaleLastPage.Enabled = false;
                this.buttonPostSaleNextPage.Enabled = false;
            }

            this.labelPostSalePage.Text = string.Format("{0} / {1}", CurrentPostSalePage, postSalePageCnt);

            AllPostSaleOrdersCacheTable          = EbayTransactionDAL.GetPagedPendingOrders(CurrentPostSalePage, PostSalePageSize, 0);
            this.dataGridViewPostSale.DataSource = AllPostSaleOrdersCacheTable;
        }
        private void ToolStripMenuItemAddRelationToItem_Click(object sender, EventArgs e)
        {
            FrmSelectItemSKU frmSelectSKU = new FrmSelectItemSKU();

            frmSelectSKU.ShowDialog();

            string itemSKU = frmSelectSKU.SKU;

            if (itemSKU == null || itemSKU == "")
            {
                return;
            }

            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)
                {
                    return;
                }

                EbayTransactionDAL.UpdateTransactionItemSKU(trans.TransactionId, itemSKU);
                row.Cells[OrderDgv_ItemSKUIndex].Value = itemSKU;
            }


            MessageBox.Show("订单关联商品sku成功", "恭喜", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
Exemplo n.º 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;
        }
Exemplo n.º 10
0
        public static bool InsertOrUpdateOneTransaction(EbayTransactionType trans)
        {
            if (trans.IsValid() == false)
            {
                return(false);
            }

            bool result = true;

            EbayTransactionType transLoc = EbayTransactionDAL.GetOneTransaction(trans.OrderLineItemId);

            if (transLoc != null)
            {
                result = UpdateOneTransaction(trans);
            }
            else
            {
                result = InsertOneTransaction(trans);
            }

            return(true);
        }
Exemplo n.º 11
0
        private List <EbayTransactionType> GetAllSelectedTransactions(bool check)
        {
            // Check if every paid-but-un-shipped item has a sku.
            List <EbayTransactionType> allSelectedTrans = new List <EbayTransactionType>();

            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)
                {
                    return(null);
                }

                if (!trans.IsPaid)
                {
                    return(null);
                }

                if (check && (trans.ItemSKU == null || trans.ItemSKU.Trim() == ""))
                {
                    MessageBox.Show("订单没有关联的商品SKU!", "失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(null);
                }

                // Is shipping service specified?
                if (check && (trans.ShippingService == "" || trans.ShippingServiceCode == ""))
                {
                    MessageBox.Show("没有为订单选择物流运输方式!", "失败", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(allSelectedTrans);
                }

                allSelectedTrans.Add(trans);
            }
            return(allSelectedTrans);
        }
Exemplo n.º 12
0
        private void LoadOrderData()
        {
            bool isDelivered = this.radioButtonDeliveredOrders.Checked;

            OrderCount = EbayTransactionDAL.GetOrdersCount(isDelivered);
            int orderPageCnt = OrderCount / OrderPageSize + 1;

            if (CurrentOrderPage < 1)
            {
                CurrentOrderPage = 1;
            }
            else if (CurrentOrderPage > orderPageCnt)
            {
                CurrentOrderPage = orderPageCnt;
            }

            this.buttonOrderFirstPage.Enabled = true;
            this.buttonOrderLastPage.Enabled  = true;
            this.buttonOrderPrevPage.Enabled  = true;
            this.buttonOrderNextPage.Enabled  = true;

            if (CurrentOrderPage == 1)
            {
                this.buttonOrderFirstPage.Enabled = false;
                this.buttonOrderPrevPage.Enabled  = false;
            }

            if (CurrentOrderPage == orderPageCnt)
            {
                this.buttonOrderLastPage.Enabled = false;
                this.buttonOrderNextPage.Enabled = false;
            }

            this.labelOrderPage.Text = string.Format("{0} / {1}", CurrentOrderPage, orderPageCnt);

            AllOrdersCacheTable = EbayTransactionDAL.GetPagedOrders(CurrentOrderPage, OrderPageSize, isShowingPendingOrders);
            this.dataGridViewAllOrders.DataSource = AllOrdersCacheTable;
        }
Exemplo n.º 13
0
        private void AddTransactionsToDataTable(String tranIdsStr)
        {
            if (tranIdsStr == "")
            {
                return;
            }

            String[] tranIds = tranIdsStr.Split(new char[] { ',', ' ' });

            foreach (String tranId in tranIds)
            {
                if (IsTransactionAlreadyAdded(tranId))
                {
                    continue;
                }

                if (IsTransactionAddedInOtherDeliveryNote(tranId))
                {
                    MessageBox.Show(String.Format("订单号{0}已被包含在其他发货单中", tranId),
                                    "抱歉", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    continue;
                }

                EbayTransactionType trans = EbayTransactionDAL.GetOneTransactonById(tranId);

                DataRow dr = mDtTransactions.NewRow();
                dr["TransactionId"] = trans.TransactionId;
                dr["SellerName"]    = trans.SellerName;
                dr["BuyerId"]       = trans.BuyerId;
                dr["BuyerCountry"]  = trans.BuyerCountry;
                dr["ItemSKU"]       = trans.ItemSKU;
                dr["ItemTitle"]     = trans.ItemTitle;
                dr["SaleQuantity"]  = trans.SaleQuantity;

                mDtTransactions.Rows.Add(dr);
            }
        }
Exemplo n.º 14
0
        public static bool UpdateOneTransaction(EbayTransactionType trans)
        {
            if (trans.IsValid() == false)
            {
                return(false);
            }

            EbayTransactionType transLoc = EbayTransactionDAL.GetOneTransaction(trans.OrderLineItemId);

            if (transLoc == null)
            {
                Logger.WriteSystemLog(string.Format("No transaction with EbayTransactionId={0}", trans.EbayTransactionId));
                return(false);
            }

            bool needUpdateIsPaid = false;

            if (trans.IsPaid != transLoc.IsPaid)
            {
                Logger.WriteSystemLog(string.Format("Update one transaction with id={0}, set isPaid={1}", trans.EbayTransactionId, trans.IsPaid));
                needUpdateIsPaid = true;
            }

            bool needUpdateShipped = false;

            if (trans.IsShipped != transLoc.IsShipped)
            {
                Logger.WriteSystemLog(string.Format("Update one transaction with id={0}, set IsShipped={1}", trans.EbayTransactionId, trans.IsShipped));
                needUpdateShipped = true;
            }

            bool needUpdateBuyerFeedbackLeft = false;

            if (trans.IsBuyerLeftFeedback != transLoc.IsBuyerLeftFeedback)
            {
                Logger.WriteSystemLog(string.Format("Update one transaction with id={0}, set BuyerFeedbackLeft={1}", trans.EbayTransactionId, trans.IsBuyerLeftFeedback));
                needUpdateBuyerFeedbackLeft = true;
            }

            bool needUpdateSellerFeedbackLeft = false;

            if (trans.IsSellerLeftFeedback != transLoc.IsSellerLeftFeedback)
            {
                Logger.WriteSystemLog(string.Format("Update one transaction with id={0}, set SellerFeedbackLeft={1}", trans.EbayTransactionId, trans.IsSellerLeftFeedback));
                needUpdateSellerFeedbackLeft = true;
            }

            bool needUpdateSellerName = false;

            if (trans.SellerName == "")
            {
                needUpdateSellerName = true;
            }

            bool needUpdateTotalPrice = false;

            if (trans.TotalPrice != transLoc.TotalPrice)
            {
                needUpdateTotalPrice = true;
            }

            bool needUpdateSaleRecordId = false;

            if (trans.EbayRecordId != -1 && trans.EbayRecordId != transLoc.EbayRecordId)
            {
                needUpdateSaleRecordId = true;
            }

            bool needUpdateSaleDateCN = false;

            if (trans.SaleDateCN != null && 0 != trans.SaleDateCN.CompareTo(transLoc.SaleDateCN))
            {
                needUpdateSaleDateCN = true;
            }

            bool needUpdateTrackingNumber = false;

            if (trans.ShippingTrackingNo != null && trans.ShippingTrackingNo != transLoc.ShippingTrackingNo)
            {
                needUpdateTrackingNumber = true;
            }

            bool needUpdateShippingDate = false;

            if (trans.ShippedDate != transLoc.ShippedDate)
            {
                needUpdateShipped = true;
            }

            if (!needUpdateIsPaid && !needUpdateShipped && !needUpdateBuyerFeedbackLeft &&
                !needUpdateSellerFeedbackLeft && !needUpdateSellerName && !needUpdateTotalPrice &&
                !needUpdateSaleRecordId && !needUpdateSaleDateCN && !needUpdateTrackingNumber && !needUpdateShippingDate)
            {
                return(true);
            }

            if (transLoc.TransactionId <= 0)
            {
                Logger.WriteSystemLog("Invalid transaction id.");
                return(false);
            }

            // CAUTION: we need to retain some column values in the old entry,
            //  such as the message status we calculated last time.
            if (transLoc.ItemSKU != null && transLoc.ItemSKU != "")
            {
                trans.ItemSKU = transLoc.ItemSKU;
            }
            if (transLoc.ShippingService != null && transLoc.ShippingService != "")
            {
                trans.ShippingService = transLoc.ShippingService;
            }
            if (transLoc.ShippingServiceCode != null && transLoc.ShippingServiceCode != "")
            {
                trans.ShippingServiceCode = transLoc.ShippingServiceCode;
            }
            trans.MessageStatus = transLoc.MessageStatus;

            bool result = UpdateOneTransactionInternal(transLoc.TransactionId, trans);

            return(result);
        }
Exemplo n.º 15
0
        private void contextMenuStripTransaction_Opening(object sender, CancelEventArgs e)
        {
            ContextMenuStrip cmnu = (ContextMenuStrip)sender;

            bool enableViewOrderDetail  = true;
            bool enableViewOrderMessage = true;

            bool enableSendMessageToBuyer = true;
            bool enableSetSKUForOrderItem = true;

            bool enableViewItem = true;

            bool enableSelectShippingService = true;
            bool enableMarkAsShipped         = true;

            bool enableCreateDeliveryNote = true;
            bool enableUploadTrackingNo   = true;
            bool enableLeaveFeedback      = true;

            bool enableMergeOrders = true;

            DataGridViewSelectedRowCollection selectedRows = this.dataGridViewAllOrders.SelectedRows;

            if (selectedRows.Count != 1)
            {
                enableViewOrderDetail    = false;
                enableViewOrderMessage   = false;
                enableSendMessageToBuyer = false;
                enableViewItem           = false;
                enableUploadTrackingNo   = false;
            }

            // First check if every transaction item has a related sku.
            String lastBuyerId = null;

            foreach (DataGridViewRow row in selectedRows)
            {
                String orderLineItemId = row.Cells[OrderDgv_OrderLineItemIndex].Value.ToString();

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

                if (lastBuyerId == null)
                {
                    lastBuyerId = trans.BuyerId;
                }
                else if (enableMergeOrders && lastBuyerId != trans.BuyerId)
                {
                    enableMergeOrders = false;
                }

                if (enableMergeOrders && trans.OrderId.IndexOf("-") < 0)
                {
                    enableMergeOrders = false;
                }

                if (trans.IsShipped || !trans.IsPaid)
                {
                    //enableSelectShippingService = false;
                    enableMarkAsShipped = false;
                }

                if (!trans.IsPaid)
                {
                    enableSelectShippingService = false;
                }

                if (enableViewOrderDetail && !trans.IsPaid)
                {
                    enableViewOrderDetail = false;
                }

                if (enableViewOrderMessage && !trans.IsPaid)
                {
                    enableViewOrderMessage = false;
                }

                if (enableSendMessageToBuyer && !trans.IsPaid)
                {
                    enableSendMessageToBuyer = false;
                }

                if (enableSetSKUForOrderItem && !trans.IsPaid)
                {
                    enableSetSKUForOrderItem = false;
                }

                if (enableViewItem && !trans.IsPaid)
                {
                    enableViewItem = false;
                }

                if (enableCreateDeliveryNote && (!trans.IsPaid || trans.IsDelivered))
                {
                    enableCreateDeliveryNote = false;
                }

                if (enableUploadTrackingNo && trans.ShippingTrackingNo != "")
                {
                    enableUploadTrackingNo = false;
                }

                if (enableLeaveFeedback && trans.IsSellerLeftFeedback)
                {
                    enableLeaveFeedback = false;
                }
            }

            cmnu.Items[ViewOrderDetailMenuItemIndex].Enabled  = enableViewOrderDetail;
            cmnu.Items[ViewOrderMessageMenuItemIndex].Enabled = enableViewOrderMessage;

            cmnu.Items[SendMessageToBuyerMenuItemIndex].Enabled = enableSendMessageToBuyer;
            cmnu.Items[SetSKUForOrderItemMenuItemIndex].Enabled = enableSetSKUForOrderItem;

            cmnu.Items[ViewItemMenuItemIndex].Enabled = enableViewItem;

            cmnu.Items[SelectShippingServiceMenuItemIndex].Enabled = enableSelectShippingService;
            cmnu.Items[MarkAsShippedMenuItemIndex].Enabled         = enableMarkAsShipped;

            cmnu.Items[UploadTrackingNoMenuItemIndex].Enabled   = enableUploadTrackingNo;
            cmnu.Items[LeaveFeedbackMenuItemIndex].Enabled      = enableLeaveFeedback;
            cmnu.Items[CreateDeliveryNoteMenuItemIndex].Enabled = enableCreateDeliveryNote;

            cmnu.Items[MergeOrdersMenuItemIndex].Enabled = enableMergeOrders;
        }
Exemplo n.º 16
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
Exemplo n.º 17
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
Exemplo n.º 18
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);
        }
Exemplo n.º 19
0
        private void ToolStripMenuItemDelDeliveryNote_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("你确认刪除该进货单么?\r\n。",
                                "确认删除?",
                                MessageBoxButtons.YesNo,
                                MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.No)
            {
                return;
            }

            int    rowIdx         = this.pagedDgvDeliveryNote.DgvData.CurrentRow.Index;
            String deliveryNoteId = this.pagedDgvDeliveryNote.DgvData.Rows[rowIdx].Cells[0].Value.ToString();

            DeliveryNoteType note = DeliveryNoteDAL.GetOneDeliveryNote(deliveryNoteId);

            if (note == null)
            {
                return;
            }

            // Restore the stock.
            String tranIdStr = note.DeliveryOrderIds;

            String[] tranIds      = tranIdStr.Split(new char[] { ',', ' ' });
            String   promptString = "";

            foreach (String tranId in tranIds)
            {
                EbayTransactionType trans = EbayTransactionDAL.GetOneTransactonById(tranId);
                if (trans == null || trans.ItemSKU == null || trans.ItemSKU == "")
                {
                    MessageBox.Show(String.Format("订单号{0}异常", tranId), "抱歉", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    continue;
                }

                String            itemSku      = trans.ItemSKU;
                int               saleQuantity = trans.SaleQuantity;
                InventoryItemType item         = ItemDAL.GetItemBySKU(itemSku);
                if (item == null)
                {
                    MessageBox.Show(String.Format("无此sku商品{0}", itemSku), "抱歉", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    continue;
                }

                ItemDAL.IncreaseItem(itemSku, saleQuantity);
                promptString += String.Format("\nsku:{0} 原库存 {1} => 现库存 {2}", itemSku, item.ItemStockNum, item.ItemStockNum + saleQuantity);

                //
                // Update transaction delivery status.
                //
                EbayTransactionDAL.UpdateTransactionDeliveryStatus(tranId, false, -1);
            }

            DeliveryNoteDAL.DeleteOneDeliveryNote(deliveryNoteId);

            pagedDgvDeliveryNote.LoadData();

            // Indicate main form to update view.
            Deleted = true;

            MessageBox.Show(String.Format("删除发货单成功 {0}", promptString),
                            "恭喜", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
Exemplo n.º 20
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;
            }
        }
        //
        // 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);
            }
        }
Exemplo n.º 22
0
        // Private to prevent misuse, use public InsertOrUpdateOneTransaction instead!!!!!!!
        private static bool InsertOneTransaction(EbayTransactionType trans)
        {
            if (trans.IsValid() == false)
            {
                return(false);
            }

            EbayTransactionType transLoc = EbayTransactionDAL.GetOneTransaction(trans.OrderLineItemId);

            if (transLoc != null)
            {
                Logger.WriteSystemLog(string.Format("Transaction already existed in database: userId={0}, itemTitle={1}",
                                                    trans.BuyerId, trans.ItemTitle));
                return(false);
            }

            IDbCommand cmd = DataFactory.CreateCommand(null);

            cmd.CommandText = @"insert into [Transaction] (SellerName, OrderId, OrderLineItemId, EbayTransactionId, EbayRecordId, BuyerId, BuyerRating,"
                              + "BuyerCountryEbayCode, BuyerCountry4PXCode,"
                              + "BuyerCountry, BuyerCompanyName, BuyerName, BuyerStateOrProvince, BuyerCity,"
                              + "BuyerTel, BuyerMail, BuyerPostalCode, BuyerAddress, BuyerAddressCompact, BuyerAddressLine1, BuyerAddressLine2,"
                              + "BuyerPayPal,ItemId, ItemTitle, ItemSKU, ItemPrice, SaleQuantity, SalePrice, TotalPrice, CurrencyId,"
                              + "SaleDate, SaleDateCN, IsPaid, PaidDate, IsShipped, ShippedDate, ShippingServiceCode, ShippingService, ShippingTrackingNo, ShippingCost, FinalValueFee, PayPalFee,"
                              + "IsReceived, IsBuyerLeftFeedback, IsSellerLeftFeedback, IsNeedAttention, MessageStatus, IsContactedBuyer,"
                              + "LastContactedBuyerDate, IsResendReplacement, UserComment) values ("
                              + "@SellerName, @OrderId, @OrderLineItemId, @EbayTransactionId, @EbayRecordId, @BuyerId, @BuyerRating,"
                              + "@BuyerCountryEbayCode, @BuyerCountry4PXCode,"
                              + "@BuyerCountry, @BuyerCompanyName, @BuyerName, @BuyerStateOrProvince, @BuyerCity,"
                              + "@BuyerTel, @BuyerMail, @BuyerPostalCode, @BuyerAddress, @BuyerAddressCompact, @BuyerAddressLine1, @BuyerAddressLine2,"
                              + "@BuyerPayPal, @ItemId, @ItemTitle, @ItemSKU, @ItemPrice, @SaleQuantity, @SalePrice, @TotalPrice, @CurrencyId,"
                              + "@SaleDate, @SaleDateCN, @IsPaid, @PaidDate, @IsShipped, @ShippedDate, @ShippingServiceCode, @ShippingService, @ShippingTrackingNo, @ShippingCost, @FinalValueFee, @PayPalFee,"
                              + "@IsReceived, @IsBuyerLeftFeedback, @IsSellerLeftFeedback, @IsNeedAttention, @MessageStatus, @IsContactedBuyer,"
                              + "@LastContactedBuyerDate, @IsResendReplacement, @UserComment)";

            DataFactory.AddCommandParam(cmd, "@SellerName", DbType.String, trans.SellerName);
            DataFactory.AddCommandParam(cmd, "@OrderId", DbType.String, trans.OrderId);
            DataFactory.AddCommandParam(cmd, "@OrderLineItemId", DbType.String, trans.OrderLineItemId);
            DataFactory.AddCommandParam(cmd, "@EbayTransactionId", DbType.String, trans.EbayTransactionId);
            DataFactory.AddCommandParam(cmd, "@EbayRecordId", DbType.Int32, trans.EbayRecordId);
            DataFactory.AddCommandParam(cmd, "@BuyerId", DbType.String, trans.BuyerId);
            DataFactory.AddCommandParam(cmd, "@BuyerRating", DbType.Int32, trans.BuyerRating);

            DataFactory.AddCommandParam(cmd, "@BuyerCountryEbayCode", DbType.String, StringUtil.GetSafeString(trans.BuyerCountryEbayCode));
            DataFactory.AddCommandParam(cmd, "@BuyerCountry4PXCode", DbType.String, StringUtil.GetSafeString(trans.BuyerCountry4PXCode));
            DataFactory.AddCommandParam(cmd, "@BuyerCountry", DbType.String, StringUtil.GetSafeString(trans.BuyerCountry));
            DataFactory.AddCommandParam(cmd, "@BuyerCompanyName", DbType.String, StringUtil.GetSafeString(trans.BuyerCompanyName));
            DataFactory.AddCommandParam(cmd, "@BuyerName", DbType.String, trans.BuyerName);

            DataFactory.AddCommandParam(cmd, "@BuyerStateOrProvince", DbType.String, trans.BuyerStateOrProvince);
            DataFactory.AddCommandParam(cmd, "@BuyerCity", DbType.String, trans.BuyerCity);
            DataFactory.AddCommandParam(cmd, "@BuyerTel", DbType.String, StringUtil.GetSafeString(trans.BuyerTel));
            DataFactory.AddCommandParam(cmd, "@BuyerMail", DbType.String, StringUtil.GetSafeString(trans.BuyerMail));
            DataFactory.AddCommandParam(cmd, "@BuyerPostalCode", DbType.String, StringUtil.GetSafeString(trans.BuyerPostalCode));

            DataFactory.AddCommandParam(cmd, "@BuyerAddress", DbType.String, StringUtil.GetSafeString(trans.BuyerAddress));
            DataFactory.AddCommandParam(cmd, "@BuyerAddressCompact", DbType.String, StringUtil.GetSafeString(trans.BuyerAddressCompact));
            DataFactory.AddCommandParam(cmd, "@BuyerAddressLine1", DbType.String, StringUtil.GetSafeString(trans.BuyerAddressLine1));
            DataFactory.AddCommandParam(cmd, "@BuyerAddressLine2", DbType.String, StringUtil.GetSafeString(trans.BuyerAddressLine2));
            DataFactory.AddCommandParam(cmd, "@BuyerPayPal", DbType.String, StringUtil.GetSafeString(trans.BuyerPayPal));
            DataFactory.AddCommandParam(cmd, "@ItemId", DbType.String, StringUtil.GetSafeString(trans.ItemId));
            DataFactory.AddCommandParam(cmd, "@ItemTitle", DbType.String, StringUtil.GetSafeString(trans.ItemTitle));

            DataFactory.AddCommandParam(cmd, "@ItemSKU", DbType.String, StringUtil.GetSafeString(trans.ItemSKU));
            DataFactory.AddCommandParam(cmd, "@ItemPrice", DbType.Double, trans.ItemPrice);
            DataFactory.AddCommandParam(cmd, "@SaleQuantity", DbType.Int32, trans.SaleQuantity);
            DataFactory.AddCommandParam(cmd, "@SalePrice", DbType.Double, trans.SalePrice);
            DataFactory.AddCommandParam(cmd, "@TotalPrice", DbType.Double, trans.TotalPrice);

            DataFactory.AddCommandParam(cmd, "@CurrencyId", DbType.String, StringUtil.GetSafeString(trans.CurrencyId));
            DataFactory.AddCommandParam(cmd, "@SaleDate", DbType.Date, StringUtil.GetSafeDateTime(trans.SaleDate).ToString());
            DataFactory.AddCommandParam(cmd, "@SaleDateCN", DbType.Date, StringUtil.GetSafeDateTime(trans.SaleDateCN).ToString());
            DataFactory.AddCommandParam(cmd, "@IsPaid", DbType.Boolean, trans.IsPaid);
            DataFactory.AddCommandParam(cmd, "@PaidDate", DbType.Date, StringUtil.GetSafeDateTime(trans.PaidDate).ToString());
            DataFactory.AddCommandParam(cmd, "@IsShipped", DbType.Boolean, trans.IsShipped);

            DataFactory.AddCommandParam(cmd, "@ShippedDate", DbType.Date, StringUtil.GetSafeDateTime(trans.ShippedDate).ToString());
            DataFactory.AddCommandParam(cmd, "@ShippingServiceCode", DbType.String, trans.ShippingServiceCode);
            DataFactory.AddCommandParam(cmd, "@ShippingService", DbType.String, trans.ShippingService);
            DataFactory.AddCommandParam(cmd, "@ShippingTrackingNo", DbType.String, trans.ShippingTrackingNo);

            DataFactory.AddCommandParam(cmd, "@ShippingCost", DbType.Double, trans.ShippingCost);
            DataFactory.AddCommandParam(cmd, "@FinalValueFee", DbType.Double, trans.FinalValueFee);
            DataFactory.AddCommandParam(cmd, "@PayPalFee", DbType.Double, trans.PayPalFee);

            DataFactory.AddCommandParam(cmd, "@IsReceived", DbType.Boolean, trans.IsReceived);
            DataFactory.AddCommandParam(cmd, "@IsBuyerLeftFeedback", DbType.Boolean, trans.IsBuyerLeftFeedback);
            DataFactory.AddCommandParam(cmd, "@IsSellerLeftFeedback", DbType.Boolean, trans.IsSellerLeftFeedback);
            DataFactory.AddCommandParam(cmd, "@IsNeedAttention", DbType.Boolean, trans.IsNeedAttention);
            DataFactory.AddCommandParam(cmd, "@MessageStatus", DbType.Int32, trans.MessageStatus);
            DataFactory.AddCommandParam(cmd, "@IsContactedBuyer", DbType.Boolean, trans.IsContactedBuyer);

            DataFactory.AddCommandParam(cmd, "@LastContactedBuyerDate", DbType.Date, StringUtil.GetSafeDateTime(trans.LastContactedBuyerDate).ToString());
            DataFactory.AddCommandParam(cmd, "@IsResendReplacement", DbType.Boolean, trans.IsResendReplacement);
            DataFactory.AddCommandParam(cmd, "@UserComment", DbType.String, StringUtil.GetSafeString(trans.UserComment));

            bool result    = false;
            int  newItemId = 0;

            try
            {
                if (DataFactory.DbConnection.State == ConnectionState.Closed)
                {
                    DataFactory.DbConnection.Open();
                }
                cmd.ExecuteNonQuery();

                IDbCommand cmdNewID = DataFactory.CreateCommand("SELECT @@IDENTITY");

                // Retrieve the Autonumber and store it in the CategoryID column.
                object obj = cmdNewID.ExecuteScalar();
                Int32.TryParse(obj.ToString(), out newItemId);
                result = newItemId > 0;
            }
            catch (DataException ex)
            {
                // Write to log here.
                Logger.WriteSystemLog(string.Format("Error : {0}", ex.Message));
                trans.dump();
                result = false;
            }
            finally
            {
                if (DataFactory.DbConnection.State == ConnectionState.Open)
                {
                    DataFactory.DbConnection.Close();
                }
            }

            return(result);
        }   // InsertOneTransaction
Exemplo n.º 23
0
        private void CreateDeliveryNote()
        {
            if (mEditMode != EditMode.CreatNew && mEditMode != EditMode.CreateFromTrans)
            {
                // We are not creating a new delivery note.
                return;
            }

            // Sanity check.
            if (mDtTransactions == null || mDtTransactions.Rows.Count == 0)
            {
                return;
            }

            //
            // Add a new delivery note.
            //

            // tranIds will be like "2264,2265,2266"
            String tranIds  = "";
            bool   firstRow = true;

            foreach (DataRow dr in mDtTransactions.Rows)
            {
                String tranIdLoc = StringUtil.GetSafeString(dr["TransactionId"]);
                if (tranIdLoc == null || tranIdLoc == "")
                {
                    continue;
                }

                if (!firstRow)
                {
                    tranIds += ",";
                }
                else
                {
                    firstRow = false;
                }

                tranIds += tranIdLoc;
            }

            double fee      = 0.0;
            double extraFee = 0.0;

            Double.TryParse(textBoxFee.Text, out fee);
            Double.TryParse(textBoxExtraFee.Text, out extraFee);

            DeliveryNoteType deliveryNote = new DeliveryNoteType();

            deliveryNote.DeliveryDate     = DateTime.Now;
            deliveryNote.DeliveryOrderIds = tranIds;
            deliveryNote.DeliveryUser     = "";
            deliveryNote.DeliveryFee      = fee;
            deliveryNote.DeliveryExtraFee = extraFee;
            deliveryNote.DeliveryComment  = textBoxComment.Text;

            // Decrease the stock.
            // Two runs:
            //  first run check validity.
            //  second run do the actual stock decreament.
            // This is to ensure the data integrity.
            Dictionary <String, int> itemSkuToTotalDecreased = new Dictionary <string, int>();

            String stockChangePrompt = "";

            for (int ii = 0; ii < 2; ++ii)
            {
                foreach (DataRow dr in mDtTransactions.Rows)
                {
                    String tranId       = StringUtil.GetSafeString(dr["TransactionId"]);
                    String itemSku      = StringUtil.GetSafeString(dr["ItemSKU"]);
                    int    saleQuantity = StringUtil.GetSafeInt(dr["SaleQuantity"]);

                    if (0 == ii)
                    {
                        if (itemSku == "")
                        {
                            MessageBox.Show(String.Format("订单{0}没有关联商品", tranId),
                                            "抱歉", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }

                        InventoryItemType item = ItemDAL.GetItemBySKU(itemSku);
                        if (item == null)
                        {
                            MessageBox.Show(String.Format("商品不存在, sku={0}", itemSku),
                                            "抱歉", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }

                        if (!itemSkuToTotalDecreased.ContainsKey(itemSku))
                        {
                            itemSkuToTotalDecreased.Add(itemSku, saleQuantity);
                        }
                        else
                        {
                            itemSkuToTotalDecreased[itemSku] += saleQuantity;
                        }

                        if (item.ItemStockNum < itemSkuToTotalDecreased[itemSku])
                        {
                            MessageBox.Show(String.Format("商品{0}库存不足,实际库存{1} < 售出数{2}",
                                                          itemSku, item.ItemStockNum, itemSkuToTotalDecreased[itemSku]),
                                            "抱歉", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                    }

                    if (1 == ii)
                    {
                        InventoryItemType item = ItemDAL.GetItemBySKU(itemSku);
                        int origStock          = item.ItemStockNum;

                        if (!ItemDAL.DecreaseItem(itemSku, saleQuantity))
                        {
                            MessageBox.Show(String.Format("更新库存失败:商品{0}库存不足销售数量{1}", itemSku, saleQuantity),
                                            "抱歉", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }

                        stockChangePrompt += String.Format("\nsku: {0}, 原库存 {1} => 现库存 {2}",
                                                           itemSku, origStock, origStock - saleQuantity);
                    }
                }
            } // End of two runs

            //
            // Create a new delivery note.
            //
            int deliveryNoteId = -1;

            if ((deliveryNoteId = DeliveryNoteDAL.InsertOneDeliveryNote(deliveryNote)) <= 0)
            {
                MessageBox.Show("创建发货单失败", "抱歉", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            //
            // Update transaction delivery status.
            //
            foreach (DataRow dr in mDtTransactions.Rows)
            {
                String tranId = StringUtil.GetSafeString(dr["TransactionId"]);
                EbayTransactionDAL.UpdateTransactionDeliveryStatus(tranId, true, deliveryNoteId);
            }

            // Indicate main form to update data.
            Added = true;

            MessageBox.Show(String.Format("创建发货单成功 {0}", stockChangePrompt),
                            "恭喜", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
Exemplo n.º 24
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