예제 #1
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
예제 #2
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);
        }