Ejemplo n.º 1
1
        public static List<EbayTransactionType> GetAllOrders(AccountType account, TimeFilter timeFilter, StringCollection orderIds)
        {
            List<EbayTransactionType> transList = new List<EbayTransactionType>();

            GetOrdersCall getOrdersApiCall = new GetOrdersCall(account.SellerApiContext);
            getOrdersApiCall.IncludeFinalValueFee = true;
            DetailLevelCodeType[] detailLevels = new DetailLevelCodeType[] { DetailLevelCodeType.ReturnAll };
            getOrdersApiCall.DetailLevelList = new DetailLevelCodeTypeCollection(detailLevels);
            if (orderIds != null)
                getOrdersApiCall.OrderIDList = orderIds;

            try
            {
                OrderTypeCollection orders = getOrdersApiCall.GetOrders(timeFilter, TradingRoleCodeType.Seller, OrderStatusCodeType.All);

                foreach (OrderType order in orders)
                {
                    AddressType addressType = order.ShippingAddress;
                    String shippingAddress = GetShippingAddressString(addressType);
                    String shippingAddressCompact = GetShippingAddressCompactString(addressType);

                    bool completed = order.OrderStatus == OrderStatusCodeType.Completed;

                    foreach (TransactionType trans in order.TransactionArray)
                    {
                        #region Process each ebay transaction
                        // Check if this transaction has already be recorded in system.
                        String transId = trans.TransactionID;
                        if (transId == null || transId == "")
                        {
                            Logger.WriteSystemLog("GetAllOrders: Invalid transaction id, skip and continue.");
                            continue;
                        }

                        EbayTransactionType ebayTrans = new EbayTransactionType();
                        ebayTrans.SellerName = account.ebayAccount;
                        ebayTrans.OrderId = order.OrderID;
                        ebayTrans.OrderLineItemId = trans.OrderLineItemID;
                        ebayTrans.EbayTransactionId = trans.TransactionID;
                        ebayTrans.EbayRecordId = order.ShippingDetails.SellingManagerSalesRecordNumberSpecified ? order.ShippingDetails.SellingManagerSalesRecordNumber : -1;
                        ebayTrans.BuyerId = order.BuyerUserID;

                        GetUserCall getUserApiCall = new GetUserCall(account.SellerApiContext);
                        getUserApiCall.UserID = order.BuyerUserID;
                        UserType user = getUserApiCall.GetUser();

                        // BuyerRating
                        if (user.FeedbackScoreSpecified)
                            ebayTrans.BuyerRating = user.FeedbackScore;
                        else
                            ebayTrans.BuyerRating = -1;

                        // BuyerCountryEbayCode
                        ebayTrans.BuyerCountryEbayCode = addressType.Country.ToString();
                        // BuyerCountry4PXCode
                        ebayTrans.BuyerCountry4PXCode = "";

                        // BuyerCountry
                        ebayTrans.BuyerCountry = addressType.CountryName;
                        // BuyerCompanyName
                        ebayTrans.BuyerCompanyName = StringUtil.GetSafeString(addressType.CompanyName);
                        // BuyerName
                        ebayTrans.BuyerName = addressType.Name;
                        // BuyerStateOrProvince
                        ebayTrans.BuyerStateOrProvince = addressType.StateOrProvince;
                        // BuyerCity
                        ebayTrans.BuyerCity = addressType.CityName;
                        // BuyerTel
                        ebayTrans.BuyerTel = addressType.Phone;
                        // BuyerMail
                        ebayTrans.BuyerMail = trans.Buyer.Email;
                        // BuyerPostalCode
                        ebayTrans.BuyerPostalCode = addressType.PostalCode;

                        // BuyerAddress
                        ebayTrans.BuyerAddress = shippingAddress;
                        // BuyerAddressCompact
                        ebayTrans.BuyerAddressCompact = shippingAddressCompact;
                        // BuyerAddressLine1
                        ebayTrans.BuyerAddressLine1 = addressType.Street1;
                        // BuyerAddressLine2
                        ebayTrans.BuyerAddressLine2 = addressType.Street2;
                        // BuyerPayPal
                        ebayTrans.BuyerPayPal = trans.Buyer.Email;

                        // ItemId
                        ebayTrans.ItemId = trans.Item.ItemID;

                        // What is the valid way to determine if there is a variation.
                        if (trans.Variation != null && trans.Variation.VariationTitle != null && trans.Variation.VariationTitle.Trim() != "")
                        {
                            // ItemTitle
                            ebayTrans.ItemTitle = trans.Variation.VariationTitle;
                            // ItemSKU
                            ebayTrans.ItemSKU = trans.Variation.SKU;
                        }
                        else
                        {
                            // ItemTitle
                            ebayTrans.ItemTitle = trans.Item.Title;
                            // ItemSKU
                            ebayTrans.ItemSKU = trans.Item.SKU;
                        }

                        // ItemPrice
                        if (trans.TransactionPrice != null)
                            ebayTrans.ItemPrice = trans.TransactionPrice.Value;
                        // SaleQuantity
                        ebayTrans.SaleQuantity = trans.QuantityPurchased;

                        if (trans.TransactionPrice != null)
                        {
                            // SalePrice
                            ebayTrans.SalePrice = trans.TransactionPrice.Value * trans.QuantityPurchased;
                            // TotalPrice
                            ebayTrans.TotalPrice = trans.TransactionPrice.Value * trans.QuantityPurchased;
                        }

                        // TODO: there may be multiple transactions in one order.
                        if (order.Total != null)
                        {
                            ebayTrans.TotalPrice = order.Total.Value;
                            ebayTrans.CurrencyId = order.Total.currencyID.ToString();
                        }
                        else
                        {
                            // Set a default value.
                            ebayTrans.TotalPrice = 0.0;
                            ebayTrans.CurrencyId = "";
                        }

                        // SaleDate
                        ebayTrans.SaleDate = order.CreatedTime;
                        // SaleDateCN
                        ebayTrans.SaleDateCN = order.CreatedTime.ToLocalTime();
                        // IsPaid
                        ebayTrans.IsPaid = order.PaidTimeSpecified;

                        // order.AmountPaid
                        // order.CheckoutStatus
                        //      ebayPaymentStatus
                        //      Status
                        // orderStatus
                        if (ebayTrans.IsPaid == false)
                        {
                            // Some payment is paid using credit card, and while PayPal is processing the payment,
                            // the transaction is marked as unpaid. we should view it as paid.
                            if (order.OrderStatusSpecified && order.OrderStatus == OrderStatusCodeType.Completed)
                                ebayTrans.IsPaid = true;
                        }

                        if (ebayTrans.IsPaid == false)
                        {
                            if (order.CheckoutStatus.StatusSpecified && order.CheckoutStatus.Status == CompleteStatusCodeType.Complete)
                                ebayTrans.IsPaid = true;
                        }

                        // PaidDate
                        ebayTrans.PaidDate = StringUtil.GetSafeDateTime(order.PaidTime);
                        // IsShipped
                        ebayTrans.IsShipped = order.ShippedTimeSpecified;
                        if (order.ShippedTimeSpecified)
                            ebayTrans.ShippedDate = StringUtil.GetSafeDateTime(order.ShippedTime);
                        else
                            ebayTrans.ShippedDate = DateTime.Now.AddYears(-10);

                        // Store the shippedDate as the local date time.
                        ebayTrans.ShippedDate = ebayTrans.ShippedDate.ToLocalTime();

                        // ShippingServiceCode
                        ebayTrans.ShippingServiceCode = "";
                        // ShippingService
                        ebayTrans.ShippingService = "";
                        // ShippingTrackingNo
                        ebayTrans.ShippingTrackingNo = "";
                        // ShippingCost
                        ebayTrans.ShippingCost = 0.0;
                        // FinalValueFee
                        if (trans.FinalValueFee != null)
                            ebayTrans.FinalValueFee = trans.FinalValueFee.Value;
                        else
                            ebayTrans.FinalValueFee = 0.0;
                        // PayPalFee
                        ebayTrans.PayPalFee = 0.034 * ebayTrans.TotalPrice + 0.3;

                        // IsReceived
                        ebayTrans.IsReceived = false;
                        ebayTrans.IsBuyerLeftFeedback = false;
                        ebayTrans.IsSellerLeftFeedback = false;
                        ebayTrans.IsNeedAttention = false;
                        ebayTrans.MessageStatus = TransactionMessageStatus.NoMessage;
                        ebayTrans.IsContactedBuyer = false;
                        ebayTrans.LastContactedBuyerDate = DateTime.Now.AddYears(-10);
                        ebayTrans.IsResendReplacement = false;
                        ebayTrans.UserComment = "";

                        GetFeedbackCall getFeedbackApiCall = new GetFeedbackCall(account.SellerApiContext);
                        //DetailLevelCodeType[] detailLevels = new DetailLevelCodeType[] { DetailLevelCodeType.ReturnAll };
                        getFeedbackApiCall.DetailLevelList = new DetailLevelCodeTypeCollection(detailLevels);
                        getFeedbackApiCall.OrderLineItemID = trans.OrderLineItemID;
                        FeedbackDetailTypeCollection feedbacks = getFeedbackApiCall.GetFeedback();
                        foreach (FeedbackDetailType feedback in feedbacks)
                        {
                            if (feedback.CommentingUser == account.ebayAccount)
                                ebayTrans.IsSellerLeftFeedback = true;

                            if (feedback.CommentingUser == ebayTrans.BuyerId)
                                ebayTrans.IsBuyerLeftFeedback = true;
                        }

                        if (trans.ShippingDetails != null)
                        {
                            if (trans.ShippingDetails.ShipmentTrackingDetails.Count == 1)
                            {
                                ShipmentTrackingDetailsType shipmentDetails = trans.ShippingDetails.ShipmentTrackingDetails[0];
                                ebayTrans.ShippingTrackingNo = shipmentDetails.ShipmentTrackingNumber;
                            }
                        }

                        transList.Add(ebayTrans);

                        #endregion
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.WriteSystemLog(string.Format("Unexpected expection : {0}", ex.Message));
            }

            return transList;
        }
Ejemplo n.º 2
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 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);
        }
Ejemplo n.º 4
0
        // Get transactions for a specified order id.
        //  Note that for single line item, only one transaction for an order.
        //  For multiple line items, they are multiple transactions for an order.
        public static List <EbayTransactionType> GetOrderTransactions(String orderId)
        {
            String    sql_getOneTransaction = "select * from [Transaction] where OrderId='" + orderId + "'";
            DataTable dt = DataFactory.ExecuteSqlReturnTable(sql_getOneTransaction);

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

            List <EbayTransactionType> trans = new List <EbayTransactionType>();

            foreach (DataRow row in dt.Rows)
            {
                EbayTransactionType tran = new EbayTransactionType();
                tran.OrderId           = orderId;
                tran.EbayTransactionId = StringUtil.GetSafeString(row["EbayTransactionId"]);
                tran.OrderLineItemId   = StringUtil.GetSafeString(row["OrderLineItemId"]);
                // ZHI_TODO:

                trans.Add(tran);
            }

            return(trans);
        }
Ejemplo 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;
        }
Ejemplo n.º 6
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();
            }
        }
Ejemplo n.º 7
0
        public FrmReplyBuyerMessage(AccountType account, EbayTransactionType trans, EbayMessageType message)
        {
            InitializeComponent();

            mTransaction = trans;
            mAccount     = account;
            mMessage     = message;
        }
Ejemplo n.º 8
0
        public FrmReplyBuyerMessage(AccountType account, EbayTransactionType trans, EbayMessageType message)
        {
            InitializeComponent();

            mTransaction = trans;
            mAccount = account;
            mMessage = message;
        }
Ejemplo n.º 9
0
        private String replaceMessageMacros(String template, EbayTransactionType trans)
        {
            if (trans == null || template == "")
            {
                return(null);
            }

            String content = template;

            content = content.Replace("{TrackingNo}", trans.ShippingTrackingNo);

            return(content);
        }
Ejemplo n.º 10
0
        public static List <EbayTransactionType> GetAllTransactions()
        {
            List <EbayTransactionType> list = new List <EbayTransactionType>();

            String    sql_getAllTransactions = "select * from [Transaction] order by SaleDate desc";
            DataTable dt = DataFactory.ExecuteSqlReturnTable(sql_getAllTransactions);

            foreach (DataRow row in dt.Rows)
            {
                EbayTransactionType trans = GetTransactionTypeFromDataRow(row);
                list.Add(trans);
            }

            return(list);
        }   // GetAllTransactions
Ejemplo n.º 11
0
        // Get transactions by input sellerName/buyerId/itemId.
        //  Note that for most cases, this function should return one entry,
        //  but it is possible that a buyer bought several items from the same list,
        //  in which case several transactions will be returned.
        public static List <EbayTransactionType> GetTransactionsBySellerBuyerItem(String sellerName, String buyerId, String itemId)
        {
            List <EbayTransactionType> transList = new List <EbayTransactionType>();

            String sql_getOneTransaction = string.Format("select * from [Transaction] where SellerName='{0}' and BuyerId='{1}' and ItemId='{2}'",
                                                         sellerName,
                                                         buyerId,
                                                         itemId);

            DataTable dt = DataFactory.ExecuteSqlReturnTable(sql_getOneTransaction);

            foreach (DataRow dr in dt.Rows)
            {
                EbayTransactionType trans = GetTransactionTypeFromDataRow(dr);
                transList.Add(trans);
            }

            return(transList);
        }
Ejemplo n.º 12
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);
        }
Ejemplo n.º 13
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);
        }
Ejemplo n.º 14
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);
            }
        }
Ejemplo n.º 15
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);
        }
Ejemplo n.º 16
0
        private static EbayTransactionType GetTransactionTypeFromDataRow(DataRow dr)
        {
            if (dr == null)
            {
                return(null);
            }

            EbayTransactionType trans = new EbayTransactionType();

            trans.TransactionId     = StringUtil.GetSafeInt(dr["TransactionId"]);
            trans.SellerName        = StringUtil.GetSafeString(dr["SellerName"]);
            trans.OrderId           = StringUtil.GetSafeString(dr["OrderId"]);
            trans.OrderLineItemId   = StringUtil.GetSafeString(dr["OrderLineItemId"]);
            trans.EbayTransactionId = StringUtil.GetSafeString(dr["EbayTransactionId"]);
            trans.EbayRecordId      = StringUtil.GetSafeInt(dr["EbayRecordId"]);

            trans.BuyerId              = StringUtil.GetSafeString(dr["BuyerId"]);
            trans.BuyerRating          = StringUtil.GetSafeInt(dr["BuyerRating"]);
            trans.BuyerCountryEbayCode = StringUtil.GetSafeString(dr["BuyerCountryEbayCode"]);
            trans.BuyerCountry4PXCode  = StringUtil.GetSafeString(dr["BuyerCountry4PXCode"]);
            trans.BuyerCountry         = StringUtil.GetSafeString(dr["BuyerCountry"]);
            trans.BuyerCompanyName     = StringUtil.GetSafeString(dr["BuyerCompanyName"]);
            trans.BuyerName            = StringUtil.GetSafeString(dr["BuyerName"]);
            trans.BuyerStateOrProvince = StringUtil.GetSafeString(dr["BuyerStateOrProvince"]);
            trans.BuyerCity            = StringUtil.GetSafeString(dr["BuyerCity"]);
            trans.BuyerTel             = StringUtil.GetSafeString(dr["BuyerTel"]);
            trans.BuyerMail            = StringUtil.GetSafeString(dr["BuyerMail"]);
            trans.BuyerPostalCode      = StringUtil.GetSafeString(dr["BuyerPostalCode"]);
            trans.BuyerAddress         = StringUtil.GetSafeString(dr["BuyerAddress"]);
            trans.BuyerAddressCompact  = StringUtil.GetSafeString(dr["BuyerAddressCompact"]);
            trans.BuyerAddressLine1    = StringUtil.GetSafeString(dr["BuyerAddressLine1"]);
            trans.BuyerAddressLine2    = StringUtil.GetSafeString(dr["BuyerAddressLine2"]);
            trans.BuyerPayPal          = StringUtil.GetSafeString(dr["BuyerPayPal"]);

            trans.ItemId       = StringUtil.GetSafeString(dr["ItemId"]);
            trans.ItemTitle    = StringUtil.GetSafeString(dr["ItemTitle"]);
            trans.ItemSKU      = StringUtil.GetSafeString(dr["ItemSKU"]);
            trans.ItemPrice    = StringUtil.GetSafeDouble(dr["ItemPrice"]);
            trans.SaleQuantity = StringUtil.GetSafeInt(dr["SaleQuantity"]);
            trans.TotalPrice   = StringUtil.GetSafeDouble(dr["TotalPrice"]);
            trans.CurrencyId   = StringUtil.GetSafeString(dr["CurrencyId"]);

            trans.SaleDate    = StringUtil.GetSafeDateTime(dr["SaleDate"]);
            trans.SaleDateCN  = StringUtil.GetSafeDateTime(dr["SaleDateCN"]);
            trans.IsPaid      = StringUtil.GetSafeBool(dr["IsPaid"]);
            trans.PaidDate    = StringUtil.GetSafeDateTime(dr["PaidDate"]);
            trans.IsShipped   = StringUtil.GetSafeBool(dr["IsShipped"]);
            trans.ShippedDate = StringUtil.GetSafeDateTime(dr["ShippedDate"]);

            trans.ShippingServiceCode = StringUtil.GetSafeString(dr["ShippingServiceCode"]);
            trans.ShippingService     = StringUtil.GetSafeString(dr["ShippingService"]);
            trans.ShippingTrackingNo  = StringUtil.GetSafeString(dr["ShippingTrackingNo"]);
            trans.ShippingCost        = StringUtil.GetSafeDouble(dr["ShippingCost"]);
            trans.FinalValueFee       = StringUtil.GetSafeDouble(dr["FinalValueFee"]);
            trans.PayPalFee           = StringUtil.GetSafeDouble(dr["PayPalFee"]);

            trans.IsReceived             = StringUtil.GetSafeBool(dr["IsReceived"]);
            trans.IsBuyerLeftFeedback    = StringUtil.GetSafeBool(dr["IsBuyerLeftFeedback"]);
            trans.IsSellerLeftFeedback   = StringUtil.GetSafeBool(dr["IsSellerLeftFeedback"]);
            trans.IsNeedAttention        = StringUtil.GetSafeBool(dr["IsNeedAttention"]);
            trans.MessageStatus          = (TransactionMessageStatus)StringUtil.GetSafeInt(dr["MessageStatus"]);
            trans.IsContactedBuyer       = StringUtil.GetSafeBool(dr["IsContactedBuyer"]);
            trans.LastContactedBuyerDate = StringUtil.GetSafeDateTime(dr["LastContactedBuyerDate"]);
            trans.IsResendReplacement    = StringUtil.GetSafeBool(dr["IsResendReplacement"]);
            trans.UserComment            = StringUtil.GetSafeString(dr["UserComment"]);

            trans.IsDelivered    = StringUtil.GetSafeBool(dr["IsDelivered"]);
            trans.DeliveryNoteId = StringUtil.GetSafeInt(dr["DeliveryNoteId"]);

            return(trans);
        } // GetTransactionTypeFromDataRow
Ejemplo n.º 17
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);
        }
Ejemplo n.º 18
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;
        }
Ejemplo n.º 19
0
        private static bool UpdateOneTransactionInternal(int transId, EbayTransactionType trans)
        {
            bool result = false;

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

            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, trans.BuyerCountryEbayCode);
            DataFactory.AddCommandParam(cmd, "@BuyerCountry4PXCode", DbType.String, trans.BuyerCountry4PXCode);
            DataFactory.AddCommandParam(cmd, "@BuyerCountry", DbType.String, trans.BuyerCountry);
            DataFactory.AddCommandParam(cmd, "@BuyerCompanyName", DbType.String, 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, trans.BuyerTel);
            DataFactory.AddCommandParam(cmd, "@BuyerMail", DbType.String, trans.BuyerMail);
            DataFactory.AddCommandParam(cmd, "@BuyerPostalCode", DbType.String, trans.BuyerPostalCode);

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

            DataFactory.AddCommandParam(cmd, "@ItemSKU", DbType.String, 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, trans.CurrencyId);
            DataFactory.AddCommandParam(cmd, "@SaleDate", DbType.DateTime, trans.SaleDate.ToString());
            DataFactory.AddCommandParam(cmd, "@SaleDateCN", DbType.DateTime, StringUtil.GetSafeDateTime(trans.SaleDateCN));
            DataFactory.AddCommandParam(cmd, "@IsPaid", DbType.Boolean, trans.IsPaid);
            DataFactory.AddCommandParam(cmd, "@PaidDate", DbType.DateTime, trans.PaidDate.ToString());
            DataFactory.AddCommandParam(cmd, "@IsShipped", DbType.Boolean, trans.IsShipped);

            DataFactory.AddCommandParam(cmd, "@ShippedDate", DbType.DateTime, 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.DateTime, trans.LastContactedBuyerDate.ToString());
            DataFactory.AddCommandParam(cmd, "@IsResendReplacement", DbType.Boolean, trans.IsResendReplacement);
            DataFactory.AddCommandParam(cmd, "@UserComment", DbType.String, trans.UserComment);

            DataFactory.AddCommandParam(cmd, "@TransactionId", DbType.String, transId);

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

            }
            catch (DataException)
            {
                // Write to log here.
                result = false;
            }
            finally
            {
                if (DataFactory.DbConnection.State == ConnectionState.Open)
                    DataFactory.DbConnection.Close();
            }

            return result;
        }
Ejemplo n.º 20
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;
        }
Ejemplo n.º 21
0
        private static EbayTransactionType GetTransactionTypeFromDataRow(DataRow dr)
        {
            if (dr == null)
                return null;

            EbayTransactionType trans = new EbayTransactionType();

            trans.TransactionId = StringUtil.GetSafeInt(dr["TransactionId"]);
            trans.SellerName = StringUtil.GetSafeString(dr["SellerName"]);
            trans.OrderId = StringUtil.GetSafeString(dr["OrderId"]);
            trans.OrderLineItemId = StringUtil.GetSafeString(dr["OrderLineItemId"]);
            trans.EbayTransactionId = StringUtil.GetSafeString(dr["EbayTransactionId"]);
            trans.EbayRecordId = StringUtil.GetSafeInt(dr["EbayRecordId"]);

            trans.BuyerId = StringUtil.GetSafeString(dr["BuyerId"]);
            trans.BuyerRating = StringUtil.GetSafeInt(dr["BuyerRating"]);
            trans.BuyerCountryEbayCode = StringUtil.GetSafeString(dr["BuyerCountryEbayCode"]);
            trans.BuyerCountry4PXCode = StringUtil.GetSafeString(dr["BuyerCountry4PXCode"]);
            trans.BuyerCountry = StringUtil.GetSafeString(dr["BuyerCountry"]);
            trans.BuyerCompanyName = StringUtil.GetSafeString(dr["BuyerCompanyName"]);
            trans.BuyerName = StringUtil.GetSafeString(dr["BuyerName"]);
            trans.BuyerStateOrProvince = StringUtil.GetSafeString(dr["BuyerStateOrProvince"]);
            trans.BuyerCity = StringUtil.GetSafeString(dr["BuyerCity"]);
            trans.BuyerTel = StringUtil.GetSafeString(dr["BuyerTel"]);
            trans.BuyerMail = StringUtil.GetSafeString(dr["BuyerMail"]);
            trans.BuyerPostalCode = StringUtil.GetSafeString(dr["BuyerPostalCode"]);
            trans.BuyerAddress = StringUtil.GetSafeString(dr["BuyerAddress"]);
            trans.BuyerAddressCompact = StringUtil.GetSafeString(dr["BuyerAddressCompact"]);
            trans.BuyerAddressLine1 = StringUtil.GetSafeString(dr["BuyerAddressLine1"]);
            trans.BuyerAddressLine2 = StringUtil.GetSafeString(dr["BuyerAddressLine2"]);
            trans.BuyerPayPal = StringUtil.GetSafeString(dr["BuyerPayPal"]);

            trans.ItemId = StringUtil.GetSafeString(dr["ItemId"]);
            trans.ItemTitle = StringUtil.GetSafeString(dr["ItemTitle"]);
            trans.ItemSKU = StringUtil.GetSafeString(dr["ItemSKU"]);
            trans.ItemPrice = StringUtil.GetSafeDouble(dr["ItemPrice"]);
            trans.SaleQuantity = StringUtil.GetSafeInt(dr["SaleQuantity"]);
            trans.TotalPrice = StringUtil.GetSafeDouble(dr["TotalPrice"]);
            trans.CurrencyId = StringUtil.GetSafeString(dr["CurrencyId"]);

            trans.SaleDate = StringUtil.GetSafeDateTime(dr["SaleDate"]);
            trans.SaleDateCN = StringUtil.GetSafeDateTime(dr["SaleDateCN"]);
            trans.IsPaid = StringUtil.GetSafeBool(dr["IsPaid"]);
            trans.PaidDate = StringUtil.GetSafeDateTime(dr["PaidDate"]);
            trans.IsShipped = StringUtil.GetSafeBool(dr["IsShipped"]);
            trans.ShippedDate = StringUtil.GetSafeDateTime(dr["ShippedDate"]);

            trans.ShippingServiceCode = StringUtil.GetSafeString(dr["ShippingServiceCode"]);
            trans.ShippingService = StringUtil.GetSafeString(dr["ShippingService"]);
            trans.ShippingTrackingNo = StringUtil.GetSafeString(dr["ShippingTrackingNo"]);
            trans.ShippingCost = StringUtil.GetSafeDouble(dr["ShippingCost"]);
            trans.FinalValueFee = StringUtil.GetSafeDouble(dr["FinalValueFee"]);
            trans.PayPalFee = StringUtil.GetSafeDouble(dr["PayPalFee"]);

            trans.IsReceived = StringUtil.GetSafeBool(dr["IsReceived"]);
            trans.IsBuyerLeftFeedback = StringUtil.GetSafeBool(dr["IsBuyerLeftFeedback"]);
            trans.IsSellerLeftFeedback = StringUtil.GetSafeBool(dr["IsSellerLeftFeedback"]);
            trans.IsNeedAttention = StringUtil.GetSafeBool(dr["IsNeedAttention"]);
            trans.MessageStatus = (TransactionMessageStatus)StringUtil.GetSafeInt(dr["MessageStatus"]);
            trans.IsContactedBuyer = StringUtil.GetSafeBool(dr["IsContactedBuyer"]);
            trans.LastContactedBuyerDate = StringUtil.GetSafeDateTime(dr["LastContactedBuyerDate"]);
            trans.IsResendReplacement = StringUtil.GetSafeBool(dr["IsResendReplacement"]);
            trans.UserComment = StringUtil.GetSafeString(dr["UserComment"]);

            trans.IsDelivered = StringUtil.GetSafeBool(dr["IsDelivered"]);
            trans.DeliveryNoteId = StringUtil.GetSafeInt(dr["DeliveryNoteId"]);

            return trans;
        }
Ejemplo n.º 22
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;
        }
Ejemplo n.º 23
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;
        }
Ejemplo n.º 24
0
        // Get transactions for a specified order id.
        //  Note that for single line item, only one transaction for an order.
        //  For multiple line items, they are multiple transactions for an order.
        public static List<EbayTransactionType> GetOrderTransactions(String orderId)
        {
            String sql_getOneTransaction = "select * from [Transaction] where OrderId='" + orderId + "'";
            DataTable dt = DataFactory.ExecuteSqlReturnTable(sql_getOneTransaction);
            if (dt.Rows.Count == 0)
                return null;

            List<EbayTransactionType> trans = new List<EbayTransactionType>();
            foreach (DataRow row in dt.Rows)
            {
                EbayTransactionType tran = new EbayTransactionType();
                tran.OrderId = orderId;
                tran.EbayTransactionId = StringUtil.GetSafeString(row["EbayTransactionId"]);
                tran.OrderLineItemId = StringUtil.GetSafeString(row["OrderLineItemId"]);
                // ZHI_TODO:

                trans.Add(tran);
            }

            return trans;
        }
Ejemplo n.º 25
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);
        }
Ejemplo n.º 26
0
        public static List <EbayTransactionType> GetAllOrders(AccountType account, TimeFilter timeFilter, StringCollection orderIds)
        {
            List <EbayTransactionType> transList = new List <EbayTransactionType>();

            GetOrdersCall getOrdersApiCall = new GetOrdersCall(account.SellerApiContext);

            getOrdersApiCall.IncludeFinalValueFee = true;
            DetailLevelCodeType[] detailLevels = new DetailLevelCodeType[] { DetailLevelCodeType.ReturnAll };
            getOrdersApiCall.DetailLevelList = new DetailLevelCodeTypeCollection(detailLevels);
            if (orderIds != null)
            {
                getOrdersApiCall.OrderIDList = orderIds;
            }

            try
            {
                OrderTypeCollection orders = getOrdersApiCall.GetOrders(timeFilter, TradingRoleCodeType.Seller, OrderStatusCodeType.All);

                foreach (OrderType order in orders)
                {
                    AddressType addressType            = order.ShippingAddress;
                    String      shippingAddress        = GetShippingAddressString(addressType);
                    String      shippingAddressCompact = GetShippingAddressCompactString(addressType);

                    bool completed = order.OrderStatus == OrderStatusCodeType.Completed;

                    foreach (TransactionType trans in order.TransactionArray)
                    {
                        #region Process each ebay transaction
                        // Check if this transaction has already be recorded in system.
                        String transId = trans.TransactionID;
                        if (transId == null || transId == "")
                        {
                            Logger.WriteSystemLog("GetAllOrders: Invalid transaction id, skip and continue.");
                            continue;
                        }

                        EbayTransactionType ebayTrans = new EbayTransactionType();
                        ebayTrans.SellerName        = account.ebayAccount;
                        ebayTrans.OrderId           = order.OrderID;
                        ebayTrans.OrderLineItemId   = trans.OrderLineItemID;
                        ebayTrans.EbayTransactionId = trans.TransactionID;
                        ebayTrans.EbayRecordId      = order.ShippingDetails.SellingManagerSalesRecordNumberSpecified ? order.ShippingDetails.SellingManagerSalesRecordNumber : -1;
                        ebayTrans.BuyerId           = order.BuyerUserID;

                        GetUserCall getUserApiCall = new GetUserCall(account.SellerApiContext);
                        getUserApiCall.UserID = order.BuyerUserID;
                        UserType user = getUserApiCall.GetUser();

                        // BuyerRating
                        if (user.FeedbackScoreSpecified)
                        {
                            ebayTrans.BuyerRating = user.FeedbackScore;
                        }
                        else
                        {
                            ebayTrans.BuyerRating = -1;
                        }

                        // BuyerCountryEbayCode
                        ebayTrans.BuyerCountryEbayCode = addressType.Country.ToString();
                        // BuyerCountry4PXCode
                        ebayTrans.BuyerCountry4PXCode = "";

                        // BuyerCountry
                        ebayTrans.BuyerCountry = addressType.CountryName;
                        // BuyerCompanyName
                        ebayTrans.BuyerCompanyName = StringUtil.GetSafeString(addressType.CompanyName);
                        // BuyerName
                        ebayTrans.BuyerName = addressType.Name;
                        // BuyerStateOrProvince
                        ebayTrans.BuyerStateOrProvince = addressType.StateOrProvince;
                        // BuyerCity
                        ebayTrans.BuyerCity = addressType.CityName;
                        // BuyerTel
                        ebayTrans.BuyerTel = addressType.Phone;
                        // BuyerMail
                        ebayTrans.BuyerMail = trans.Buyer.Email;
                        // BuyerPostalCode
                        ebayTrans.BuyerPostalCode = addressType.PostalCode;

                        // BuyerAddress
                        ebayTrans.BuyerAddress = shippingAddress;
                        // BuyerAddressCompact
                        ebayTrans.BuyerAddressCompact = shippingAddressCompact;
                        // BuyerAddressLine1
                        ebayTrans.BuyerAddressLine1 = addressType.Street1;
                        // BuyerAddressLine2
                        ebayTrans.BuyerAddressLine2 = addressType.Street2;
                        // BuyerPayPal
                        ebayTrans.BuyerPayPal = trans.Buyer.Email;

                        // ItemId
                        ebayTrans.ItemId = trans.Item.ItemID;

                        // What is the valid way to determine if there is a variation.
                        if (trans.Variation != null && trans.Variation.VariationTitle != null && trans.Variation.VariationTitle.Trim() != "")
                        {
                            // ItemTitle
                            ebayTrans.ItemTitle = trans.Variation.VariationTitle;
                            // ItemSKU
                            ebayTrans.ItemSKU = trans.Variation.SKU;
                        }
                        else
                        {
                            // ItemTitle
                            ebayTrans.ItemTitle = trans.Item.Title;
                            // ItemSKU
                            ebayTrans.ItemSKU = trans.Item.SKU;
                        }

                        // ItemPrice
                        if (trans.TransactionPrice != null)
                        {
                            ebayTrans.ItemPrice = trans.TransactionPrice.Value;
                        }
                        // SaleQuantity
                        ebayTrans.SaleQuantity = trans.QuantityPurchased;

                        if (trans.TransactionPrice != null)
                        {
                            // SalePrice
                            ebayTrans.SalePrice = trans.TransactionPrice.Value * trans.QuantityPurchased;
                            // TotalPrice
                            ebayTrans.TotalPrice = trans.TransactionPrice.Value * trans.QuantityPurchased;
                        }

                        // TODO: there may be multiple transactions in one order.
                        if (order.Total != null)
                        {
                            ebayTrans.TotalPrice = order.Total.Value;
                            ebayTrans.CurrencyId = order.Total.currencyID.ToString();
                        }
                        else
                        {
                            // Set a default value.
                            ebayTrans.TotalPrice = 0.0;
                            ebayTrans.CurrencyId = "";
                        }

                        // SaleDate
                        ebayTrans.SaleDate = order.CreatedTime;
                        // SaleDateCN
                        ebayTrans.SaleDateCN = order.CreatedTime.ToLocalTime();
                        // IsPaid
                        ebayTrans.IsPaid = order.PaidTimeSpecified;

                        // order.AmountPaid
                        // order.CheckoutStatus
                        //      ebayPaymentStatus
                        //      Status
                        // orderStatus
                        if (ebayTrans.IsPaid == false)
                        {
                            // Some payment is paid using credit card, and while PayPal is processing the payment,
                            // the transaction is marked as unpaid. we should view it as paid.
                            if (order.OrderStatusSpecified && order.OrderStatus == OrderStatusCodeType.Completed)
                            {
                                ebayTrans.IsPaid = true;
                            }
                        }

                        if (ebayTrans.IsPaid == false)
                        {
                            if (order.CheckoutStatus.StatusSpecified && order.CheckoutStatus.Status == CompleteStatusCodeType.Complete)
                            {
                                ebayTrans.IsPaid = true;
                            }
                        }

                        // PaidDate
                        ebayTrans.PaidDate = StringUtil.GetSafeDateTime(order.PaidTime);
                        // IsShipped
                        ebayTrans.IsShipped = order.ShippedTimeSpecified;
                        if (order.ShippedTimeSpecified)
                        {
                            ebayTrans.ShippedDate = StringUtil.GetSafeDateTime(order.ShippedTime);
                        }
                        else
                        {
                            ebayTrans.ShippedDate = DateTime.Now.AddYears(-10);
                        }

                        // Store the shippedDate as the local date time.
                        ebayTrans.ShippedDate = ebayTrans.ShippedDate.ToLocalTime();

                        // ShippingServiceCode
                        ebayTrans.ShippingServiceCode = "";
                        // ShippingService
                        ebayTrans.ShippingService = "";
                        // ShippingTrackingNo
                        ebayTrans.ShippingTrackingNo = "";
                        // ShippingCost
                        ebayTrans.ShippingCost = 0.0;
                        // FinalValueFee
                        if (trans.FinalValueFee != null)
                        {
                            ebayTrans.FinalValueFee = trans.FinalValueFee.Value;
                        }
                        else
                        {
                            ebayTrans.FinalValueFee = 0.0;
                        }
                        // PayPalFee
                        ebayTrans.PayPalFee = 0.034 * ebayTrans.TotalPrice + 0.3;

                        // IsReceived
                        ebayTrans.IsReceived             = false;
                        ebayTrans.IsBuyerLeftFeedback    = false;
                        ebayTrans.IsSellerLeftFeedback   = false;
                        ebayTrans.IsNeedAttention        = false;
                        ebayTrans.MessageStatus          = TransactionMessageStatus.NoMessage;
                        ebayTrans.IsContactedBuyer       = false;
                        ebayTrans.LastContactedBuyerDate = DateTime.Now.AddYears(-10);
                        ebayTrans.IsResendReplacement    = false;
                        ebayTrans.UserComment            = "";

                        GetFeedbackCall getFeedbackApiCall = new GetFeedbackCall(account.SellerApiContext);
                        //DetailLevelCodeType[] detailLevels = new DetailLevelCodeType[] { DetailLevelCodeType.ReturnAll };
                        getFeedbackApiCall.DetailLevelList = new DetailLevelCodeTypeCollection(detailLevels);
                        getFeedbackApiCall.OrderLineItemID = trans.OrderLineItemID;
                        FeedbackDetailTypeCollection feedbacks = getFeedbackApiCall.GetFeedback();
                        foreach (FeedbackDetailType feedback in feedbacks)
                        {
                            if (feedback.CommentingUser == account.ebayAccount)
                            {
                                ebayTrans.IsSellerLeftFeedback = true;
                            }

                            if (feedback.CommentingUser == ebayTrans.BuyerId)
                            {
                                ebayTrans.IsBuyerLeftFeedback = true;
                            }
                        }

                        if (trans.ShippingDetails != null)
                        {
                            if (trans.ShippingDetails.ShipmentTrackingDetails.Count == 1)
                            {
                                ShipmentTrackingDetailsType shipmentDetails = trans.ShippingDetails.ShipmentTrackingDetails[0];
                                ebayTrans.ShippingTrackingNo = shipmentDetails.ShipmentTrackingNumber;
                            }
                        }

                        transList.Add(ebayTrans);

                        #endregion
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.WriteSystemLog(string.Format("Unexpected expection : {0}", ex.Message));
            }

            return(transList);
        }   // GetAllOrders
Ejemplo n.º 27
0
        private static bool UpdateOneTransactionInternal(int transId, EbayTransactionType trans)
        {
            bool result = false;

            IDbCommand cmd = DataFactory.CreateCommand(null);

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

            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, trans.BuyerCountryEbayCode);
            DataFactory.AddCommandParam(cmd, "@BuyerCountry4PXCode", DbType.String, trans.BuyerCountry4PXCode);
            DataFactory.AddCommandParam(cmd, "@BuyerCountry", DbType.String, trans.BuyerCountry);
            DataFactory.AddCommandParam(cmd, "@BuyerCompanyName", DbType.String, 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, trans.BuyerTel);
            DataFactory.AddCommandParam(cmd, "@BuyerMail", DbType.String, trans.BuyerMail);
            DataFactory.AddCommandParam(cmd, "@BuyerPostalCode", DbType.String, trans.BuyerPostalCode);

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

            DataFactory.AddCommandParam(cmd, "@ItemSKU", DbType.String, 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, trans.CurrencyId);
            DataFactory.AddCommandParam(cmd, "@SaleDate", DbType.DateTime, trans.SaleDate.ToString());
            DataFactory.AddCommandParam(cmd, "@SaleDateCN", DbType.DateTime, StringUtil.GetSafeDateTime(trans.SaleDateCN));
            DataFactory.AddCommandParam(cmd, "@IsPaid", DbType.Boolean, trans.IsPaid);
            DataFactory.AddCommandParam(cmd, "@PaidDate", DbType.DateTime, trans.PaidDate.ToString());
            DataFactory.AddCommandParam(cmd, "@IsShipped", DbType.Boolean, trans.IsShipped);

            DataFactory.AddCommandParam(cmd, "@ShippedDate", DbType.DateTime, 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.DateTime, trans.LastContactedBuyerDate.ToString());
            DataFactory.AddCommandParam(cmd, "@IsResendReplacement", DbType.Boolean, trans.IsResendReplacement);
            DataFactory.AddCommandParam(cmd, "@UserComment", DbType.String, trans.UserComment);

            DataFactory.AddCommandParam(cmd, "@TransactionId", DbType.String, transId);

            try
            {
                if (DataFactory.DbConnection.State == ConnectionState.Closed)
                {
                    DataFactory.DbConnection.Open();
                }
                cmd.ExecuteNonQuery();
                result = true;
            }
            catch (DataException)
            {
                // Write to log here.
                result = false;
            }
            finally
            {
                if (DataFactory.DbConnection.State == ConnectionState.Open)
                {
                    DataFactory.DbConnection.Close();
                }
            }

            return(result);
        }
Ejemplo n.º 28
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
        //
        // 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);
            }
        }
Ejemplo n.º 30
0
        private String replaceMessageMacros(String template, EbayTransactionType trans)
        {
            if (trans == null || template == "")
                return null;

            String content = template;
            content = content.Replace("{TrackingNo}", trans.ShippingTrackingNo);

            return content;
        }
Ejemplo n.º 31
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