示例#1
0
        public ReturnValue PostOrder(TOrder order, EntityList orderline)
        {
            ReturnValue _result = new ReturnValue();


            VCBusiness.VeraCoreOMS.Order Order = new VeraCoreOMS.Order();


            VCBusiness.VeraCoreOMS.OrderedBy OrderedBy = new VeraCoreOMS.OrderedBy();

            if (string.IsNullOrWhiteSpace(order.B_ADDRESS1) == true && string.IsNullOrWhiteSpace(order.B_STATE) == true)
            {
                OrderedBy.Address1    = order.D_ADDRESS1;
                OrderedBy.Address2    = order.D_ADDRESS2;
                OrderedBy.City        = order.D_CITY;
                OrderedBy.CompanyName = order.D_COMPANY;
                OrderedBy.Country     = order.D_COUNTRY;
                OrderedBy.Email       = order.D_EMAIL;
                OrderedBy.FirstName   = order.D_FIRSTNAME;
                OrderedBy.LastName    = order.D_LASTNAME;
                OrderedBy.Phone       = order.D_PHONE;
                OrderedBy.PostalCode  = order.D_ZIP;
                OrderedBy.State       = order.D_STATE;
            }
            else
            {
                OrderedBy.Address1    = order.B_ADDRESS1;
                OrderedBy.Address2    = order.B_ADDRESS2;
                OrderedBy.City        = order.B_CITY;
                OrderedBy.CompanyName = order.B_COMPANY;
                OrderedBy.Country     = order.B_COUNTRY;
                OrderedBy.Email       = order.B_EMAIL;
                OrderedBy.FirstName   = order.B_FIRSTNAME;
                OrderedBy.LastName    = order.B_LASTNAME;
                OrderedBy.Phone       = order.B_PHONE;
                OrderedBy.PostalCode  = order.B_ZIP;
                OrderedBy.State       = order.B_STATE;
            }



            Order.OrderedBy = OrderedBy;

            if (string.IsNullOrWhiteSpace(order.D_ADDRESS1) == false)
            {
                VCBusiness.VeraCoreOMS.OrderBillTo OrderBillTo = new VeraCoreOMS.OrderBillTo();
                OrderBillTo.Address1    = order.D_ADDRESS1;
                OrderBillTo.Address2    = order.D_ADDRESS2;
                OrderBillTo.City        = order.D_CITY;
                OrderBillTo.CompanyName = order.D_COMPANY;
                OrderBillTo.Country     = order.D_COUNTRY;
                OrderBillTo.Email       = order.D_EMAIL;
                OrderBillTo.FirstName   = order.D_FIRSTNAME;
                OrderBillTo.LastName    = order.D_LASTNAME;
                OrderBillTo.Phone       = order.D_PHONE;
                OrderBillTo.PostalCode  = order.D_ZIP;
                OrderBillTo.State       = order.D_STATE;

                Order.BillTo = OrderBillTo;
            }


            TOrder_Line_Item orderItem = orderline[0] as TOrder_Line_Item;

            VCBusiness.VeraCoreOMS.OrderShipTo OrderShipTo = new VCBusiness.VeraCoreOMS.OrderShipTo();
            OrderShipTo.Address1    = orderItem.S_ADDRESS1;
            OrderShipTo.Address2    = orderItem.S_ADDRESS2;
            OrderShipTo.City        = orderItem.S_CITY;
            OrderShipTo.CompanyName = orderItem.S_COMPANY;
            OrderShipTo.Country     = orderItem.S_COUNTRY;
            OrderShipTo.Email       = orderItem.S_EMAIL;
            OrderShipTo.FirstName   = orderItem.S_FIRSTNAME;
            OrderShipTo.LastName    = orderItem.S_LASTNAME;
            OrderShipTo.Phone       = orderItem.S_PHONE;
            OrderShipTo.PostalCode  = orderItem.S_ZIP;
            OrderShipTo.State       = orderItem.S_STATE;
            if (order.ExpectedShipDate != null)
            {
                OrderShipTo.NeededBy = order.ExpectedShipDate.ToString();
            }

            if (string.IsNullOrWhiteSpace(order.ShippingAccountNumber) == false)
            {
                OrderShipTo.ThirdPartyAccountNumber = order.ShippingAccountNumber;
            }

            if (Convert.ToBoolean(System.Configuration.ConfigurationSettings.AppSettings["IsTestMode"].ToString()) == true)
            {
                OrderShipTo.FreightService             = new VCBusiness.VeraCoreOMS.FreightService();
                OrderShipTo.FreightService.Description = "Standard";

                OrderShipTo.FreightCarrier      = new VCBusiness.VeraCoreOMS.FreightCarrier();
                OrderShipTo.FreightCarrier.Name = "USPS";
            }
            else
            {
                //OrderShipTo.FreightCarrier = new VCBusiness.VeraCoreOMS.FreightCarrier();
                //OrderShipTo.FreightCarrier.Name = orderItem.ShipCarrier;

                //OrderShipTo.FreightService = new VCBusiness.VeraCoreOMS.FreightService();
                //OrderShipTo.FreightService.Description = orderItem.ShipMethod;

                ShippingOption ShippingOption = new ShippingOption();
                ShippingOption.Description = orderItem.ShipMethod;

                OrderShipping OrderShipping = new VeraCoreOMS.OrderShipping();
                OrderShipping.ShippingOption = ShippingOption;

                Order.Shipping = OrderShipping;
            }

            OrderShipTo.Key  = "0";
            OrderShipTo.Flag = VCBusiness.VeraCoreOMS.ShipToFlag.Other;

            Order.ShipTo    = new VCBusiness.VeraCoreOMS.OrderShipTo[1];
            Order.ShipTo[0] = OrderShipTo;

            Order.Header                 = new VCBusiness.VeraCoreOMS.OrderHeader();
            Order.Header.ID              = order.OrderId.ToString();
            Order.Header.EntryDate       = System.DateTime.Now;
            Order.Header.InsertDate      = System.DateTime.Now;
            Order.Header.ReferenceNumber = order.AltOrderNum;

            Order.Classification            = new OrderClassification();
            Order.Classification.CampaignID = order.PartyCode;


            Order.Offers = new VCBusiness.VeraCoreOMS.OfferOrdered[orderline.Count];

            int i = 0;

            foreach (TOrder_Line_Item _line in orderline)
            {
                VCBusiness.VeraCoreOMS.OfferOrdered OfferOrdered = new VCBusiness.VeraCoreOMS.OfferOrdered();
                OfferOrdered.LineNumber      = i;
                OfferOrdered.LineTaxAmount   = 0;
                OfferOrdered.Quantity        = _line.Quantity;
                OfferOrdered.OrderShipTo     = new VCBusiness.VeraCoreOMS.OrderShipToKey();
                OfferOrdered.OrderShipTo.Key = "0";
                OfferOrdered.Offer           = new VCBusiness.VeraCoreOMS.OfferID();
                OfferOrdered.Offer.Header    = new VCBusiness.VeraCoreOMS.OfferIDHeader();
                OfferOrdered.Offer.Header.ID = _line.PartNumber;
                OfferOrdered.UnitPrice       = Convert.ToDecimal(_line.Price);


                OfferOrdered.ProductDetails               = new VCBusiness.VeraCoreOMS.OrderProductDetail[1];
                OfferOrdered.ProductDetails[0]            = new VCBusiness.VeraCoreOMS.OrderProductDetail();
                OfferOrdered.ProductDetails[0].PartNumber = _line.PartNumber;
                Order.Offers[i] = OfferOrdered;

                i++;


                if (Convert.ToBoolean(System.Configuration.ConfigurationSettings.AppSettings["IsTestMode"].ToString()) == true)
                {
                    this.PostProduct(VCBusiness.Common.OwnerCode, _line.PartNumber, _line.ProductName);
                }
            }

            try
            {
                requestXml = WComm.XmlSerializer.Serialize(Order);

                VCBusiness.VeraCoreOMS.AddOrderResult orderResult = OMSSoapClient.AddOrder(AuthenticationHeader, ref DebugHeader, Order);

                responseXml = WComm.XmlSerializer.Serialize(orderResult);

                Common.Log(requestXml, responseXml, "PostOrder", order.OrderId.ToString(), true, null);
            }
            catch (Exception ex)
            {
                _result.ErrMessage = ex.ToString();
                _result.Success    = false;

                Common.Log(requestXml, responseXml, "PostOrder", order.OrderId.ToString(), false, _result.ErrMessage);
            }



            return(_result);
        }
示例#2
0
        private ReturnValue createZOrder(ShipStationResponseOrder order)
        {
            ReturnValue _result = new ReturnValue();

            int _sourceId = int.Parse(ConfigurationSettings.AppSettings["SourceId"]);
            int programID = int.Parse(order.advancedOptions.customField1);


            TOrder _tOrder = new TOrder();

            #region get OrderTypeId

            if (string.IsNullOrWhiteSpace(order.advancedOptions.customField3) == true)
            {
                _result.ErrMessage = string.Format("OrderType({0}) is empty. ", order.advancedOptions.customField3);
                _result.Success    = false;
                return(_result);
            }

            var itemType = Types.Find(s => s.Code.Equals(order.advancedOptions.customField3, StringComparison.OrdinalIgnoreCase));
            if (itemType == null)
            {
                if (Common.AutoCreateProduct == true)
                {
                    TType _tType = new TType();
                    _tType.Code            = order.advancedOptions.customField3;
                    _tType.ContentStatusId = 1;
                    _tType.Description     = order.advancedOptions.customField3;
                    _tType.GroupBy         = "ORDER";
                    _tType.CreatedOn       = System.DateTime.Now;
                    _result = _tType.Save();

                    _tType.TypeId = _result.IdentityId;
                    itemType      = _tType;

                    Types.Add(_tType);
                }
                else
                {
                    _result.ErrMessage = string.Format("OrderType({0}) can not be found. ", order.advancedOptions.customField3);
                    _result.Success    = false;
                    return(_result);
                }
            }

            _tOrder.OrderTypeId = itemType.TypeId;

            #endregion

            #region get ShipMethod

            if (string.IsNullOrWhiteSpace(order.advancedOptions.customField2) == true)
            {
                _result.ErrMessage = string.Format("ShipMethod({0}) is empty. ", order.advancedOptions.customField2);
                _result.Success    = false;
                return(_result);
            }

            var method = ShipMethods.Find(s => s.Code.Equals(order.advancedOptions.customField2, StringComparison.OrdinalIgnoreCase));
            if (method == null)
            {
                _result.ErrMessage = string.Format("ShipMethod({0}) can not be found. ", order.advancedOptions.customField2);
                _result.Success    = false;
                return(_result);
            }

            int shipMethodId = method.ShipMethodId;

            #endregion

            #region Address

            if (order.shipTo.phone != null)
            {
                order.shipTo.phone = order.shipTo.phone.Replace("+", "");
                if (order.shipTo.phone.Length > 13)
                {
                    order.shipTo.phone = "0000000000";
                }
            }
            if (string.IsNullOrWhiteSpace(order.shipTo.state) && order.shipTo.country != "US" && order.shipTo.country != "CA")
            {
                order.shipTo.state = "XX";
            }

            var address = new TAddress();

            var country = Countrys.Find(c => c.ISO2.Equals(order.shipTo.country, StringComparison.OrdinalIgnoreCase));
            if (country == null)
            {
                _result.ErrMessage = string.Format("Country({0}) can not be found. ", order.shipTo.country);
                _result.Success    = false;
                return(_result);
            }
            address.CountryId = country.CountryId;

            var state = States.Find(c => c.Code.Equals(order.shipTo.state, StringComparison.OrdinalIgnoreCase));
            if (state == null && order.shipTo.country != "US" && order.shipTo.country != "CA")
            {
                order.shipTo.state = "XX";
                state = States.Find(c => c.Code.Equals(order.shipTo.state, StringComparison.OrdinalIgnoreCase));
            }

            if (state == null)
            {
                _result.ErrMessage = string.Format("State({0}) can not be found. ", order.shipTo.state);
                _result.Success    = false;
                return(_result);
            }
            address.StateId = state.StateId;



            address.Address1 = order.shipTo.street1;
            address.Address2 = order.shipTo.street2;
            address.Address3 = order.shipTo.street3;
            if (address.Address1 == null)
            {
                address.Address1 = "";
            }
            if (address.Address2 == null)
            {
                address.Address2 = "";
            }
            if (address.Address3 == null)
            {
                address.Address3 = "";
            }

            if (address.Address1.Length > 35 || address.Address2.Length > 35 || address.Address3.Length > 35)
            {
                var temp = address.Address1 + " " + address.Address2 + " " + address.Address3;
                address.Address1 = temp.Substring(0, 35);
                temp             = temp.Substring(35);
                if (temp.Length > 35)
                {
                    address.Address2 = temp.Substring(0, 35);
                    temp             = temp.Substring(35);
                }
                else
                {
                    address.Address2 = temp;
                    temp             = "";
                }
                if (temp.Length > 35)
                {
                    address.Address3 = temp.Substring(0, 35);
                }
                else
                {
                    address.Address3 = temp;
                }
            }

            address.City       = order.shipTo.city;
            address.PostalCode = order.shipTo.postalCode;
            address.UpdatedOn  = DateTime.Now;
            address.ProgramId  = programID;

            _tOrder.Address = address;


            #endregion

            #region Customer

            var customer = new TCustomer();
            customer.SourceId  = _sourceId;
            customer.ProgramId = programID;
            customer.FirstName = order.shipTo.fname;
            customer.LastName  = order.shipTo.lname;
            customer.Email     = order.customerEmail;
            customer.Company   = order.shipTo.company;
            customer.CreatedOn = System.DateTime.Now;

            if (programID == 463)
            {
                customer.AltCustNum = "ONL" + order.orderNumber.ToString();
            }

            _tOrder.Customer = customer;

            #endregion

            #region Item Line

            #region   skip the SKU when importing if the SKU=’’ and fulfillmentsku=null and name like ‘coupon%’

            var query = order.items.Where(u =>
                                          (!string.IsNullOrEmpty(u.sku) || !string.IsNullOrEmpty(u.fulfillmentSku) || !u.name.ToLower().StartsWith("coupon"))
                                          );

            order.items = query.ToList <ShipStationResponseItem>();

            foreach (ShipStationResponseItem sitem in order.items)
            {
                if (sitem.sku == "" && string.IsNullOrEmpty(sitem.fulfillmentSku) && sitem.name.ToLower().IndexOf("coupon") == 0)
                {
                    order.items.Remove(sitem);
                }
            }

            #endregion


            var lineNum = 1;

            foreach (var lineItem in order.items)
            {
                var sku = string.IsNullOrEmpty(lineItem.fulfillmentSku) ? lineItem.sku : lineItem.fulfillmentSku;
                if (string.IsNullOrWhiteSpace(sku) == true)
                {
                    _result.ErrMessage = string.Format("SKU({0}) is empty.", sku);
                    _result.Success    = false;
                    return(_result);
                }



                var productItem = Products.Find(s => s.PartNumber != null && s.PartNumber.Equals(sku, StringComparison.OrdinalIgnoreCase) && s.ProgramId == programID);
                if (productItem == null)
                {
                    if (Common.AutoCreateProduct == true)
                    {
                        TProduct _tProduct = new TProduct();
                        _tProduct.PartNumber = sku;
                        _tProduct.Name       = lineItem.name;
                        _tProduct.ProgramID  = programID;

                        _result             = _tProduct.Save();
                        _tProduct.ProductId = _result.IdentityId;

                        TProgram_Product _tProgram_Product = new TProgram_Product();
                        _tProgram_Product.PartNumber      = sku;
                        _tProgram_Product.Name            = sku;
                        _tProgram_Product.ProgramId       = programID;
                        _tProgram_Product.ContentStatusId = 1;
                        _tProgram_Product.ProductId       = _tProduct.ProductId;

                        _result = _tProgram_Product.Save();

                        _tProgram_Product.ProgramProductId = _result.IdentityId;
                        productItem = _tProgram_Product;

                        Products.Add(_tProgram_Product);
                    }
                    else
                    {
                        _result.ErrMessage = string.Format("SKU({0}) can not be found. ", sku);
                        _result.Success    = false;
                        return(_result);
                    }
                }

                TOrder_Line_Item _tOrder_Line_Item = new TOrder_Line_Item();
                _tOrder_Line_Item.ProgramProductId  = productItem.ProgramProductId;
                _tOrder_Line_Item.PartNumber        = productItem.PartNumber;
                _tOrder_Line_Item.ProductName       = lineItem.name;
                _tOrder_Line_Item.Quantity          = lineItem.quantity;
                _tOrder_Line_Item.Price             = Convert.ToDouble(lineItem.unitPrice);
                _tOrder_Line_Item.ActualPrice       = _tOrder_Line_Item.Quantity * _tOrder_Line_Item.Price;
                _tOrder_Line_Item.OrderLineItemDate = lineItem.createDate;

                _tOrder_Line_Item.ShipToCustomerId = _tOrder.CustomerId;
                _tOrder_Line_Item.ShipToAddressId  = _tOrder.CustomerAddressId;
                _tOrder_Line_Item.ShipMethodId     = shipMethodId;
                _tOrder_Line_Item.LineNum          = lineNum;
                lineNum++;

                _tOrder.OrderLines.Add(_tOrder_Line_Item);
            }



            #endregion

            #region Order level

            _tOrder.AltOrderNum        = order.orderNumber.ToString();
            _tOrder.OrderDate          = order.orderDate;
            _tOrder.TotalOrderAmount   = Convert.ToDouble(order.orderTotal);
            _tOrder.TotalTax           = Convert.ToDouble(order.taxAmount);
            _tOrder.TotalShipping      = Convert.ToDouble(order.shippingAmount);
            _tOrder.TotalProductAmount = Convert.ToDouble(order.orderTotal - order.taxAmount - order.shippingAmount);
            _tOrder.ProgramId          = programID;
            _tOrder.SourceId           = _sourceId;
            _tOrder.StatusCode         = "AS";

            #endregion

            _result.Object = _tOrder;

            return(_result);
        }
示例#3
0
        public ReturnValue GetOrderShipmentInfo(string orderid)
        {
            ReturnValue _result = new ReturnValue();


            try
            {
                requestXml = orderid;


                VCBusiness.VeraCoreOMS.OrderInqRecord orderInqRecord = OMSSoapClient.GetOrderInfo(AuthenticationHeader, ref DebugHeader, orderid);

                responseXml = WComm.XmlSerializer.Serialize(orderInqRecord);

                Common.Log(requestXml, responseXml, "GetOrderShipmentInfo", orderid.ToString(), true, null);

                TOrder_Line_Item _tOrder_Line_Item = new TOrder_Line_Item();

                _tOrder_Line_Item.ShipCarrier   = orderInqRecord.OrdHead.Carrier;
                _tOrder_Line_Item.ShipMethod    = orderInqRecord.OrdHead.Service;
                _tOrder_Line_Item.ShipToAddress = orderInqRecord.ShipToInfo.Address1;
                _tOrder_Line_Item.ShipToCity    = orderInqRecord.ShipToInfo.City;
                _tOrder_Line_Item.ShipToState   = orderInqRecord.ShipToInfo.State;
                _tOrder_Line_Item.ShipToZip     = orderInqRecord.ShipToInfo.PostalCode;

                EntityList lineList = new EntityList();


                foreach (PickPackType itemPackage in orderInqRecord.ShippingOrders)
                {
                    foreach (PackagesType item in itemPackage.Packages)
                    {
                        if (item.DateShipped.Year != 1)
                        {
                            _tOrder_Line_Item.ShippedDate    = item.DateShipped;
                            _tOrder_Line_Item.TrackingNumber = item.TrackingId;
                            _tOrder_Line_Item.ShipMethod     = item.Service;
                            _tOrder_Line_Item.ShipCarrier    = item.Carrier;
                            break;
                        }
                    }

                    if (_tOrder_Line_Item.ShippedDate != null)
                    {
                        foreach (PickPackProductType product in itemPackage.PickPackProducts)
                        {
                            TOrder_Line_Item productItem = _tOrder_Line_Item.Clone() as TOrder_Line_Item;

                            productItem.PartNumber  = product.ProductId;
                            productItem.ProductName = product.ProductDesc;
                            productItem.Quantity    = product.ToShipQty;
                            lineList.Add(productItem);
                        }
                    }
                }

                _result.ObjectList = lineList;
            }
            catch (Exception ex)
            {
                _result.Success    = false;
                _result.ErrMessage = ex.ToString();

                Common.Log(requestXml, responseXml, "GetOrderShipmentInfo", orderid.ToString(), false, _result.ErrMessage);


                return(_result);
            }

            return(_result);
        }
示例#4
0
        public override ReturnValue GetMailContent(int orderId, int releaseID, TProgram_Email mi)
        {
            ReturnValue _result = new ReturnValue();


            System.Globalization.NumberFormatInfo nfi = Utilities.CurrentNumberFormat;

            #region getCustomerInfo
            TOrderTF _tOrder = new TOrderTF();
            _result = _tOrder.getOrderById(orderId);
            if (!_result.Success)
            {
                return(_result);
            }
            _tOrder = _result.Object as TOrderTF;

            if (_tOrder.SourceId == 19)
            {
                _result.Code = 19;
                return(_result);
            }


            TCustomer _tCustomer = new TCustomer();
            _result = _tCustomer.getCustomerById(_tOrder.PWPCustomerId);
            if (!_result.Success)
            {
                return(_result);
            }
            _tCustomer = _result.Object as TCustomer;



            TOrder_Line_Item _tOrder_Line_Item = new TOrder_Line_Item();
            _result = _tOrder_Line_Item.getOrderDetailsByOrderId(_tOrder.OrderId, releaseID);
            if (!_result.Success)
            {
                return(_result);
            }
            EntityList _list = _result.ObjectList;

            if (_list.Count == 0)
            {
                return(_result);
            }

            _tOrder_Line_Item = _list[0] as TOrder_Line_Item;

            TShipMethod _tShipMethod = new TShipMethod();
            _result = _tShipMethod.getShipMethodById(_tOrder_Line_Item.ShipMethodId);
            if (!_result.Success)
            {
                return(_result);
            }
            _tShipMethod = _result.Object as TShipMethod;


            TAddress _tBillAddress = new TAddress();
            _result = _tBillAddress.getAddressById(_tOrder.CustomerAddressId);
            if (!_result.Success)
            {
                return(_result);
            }
            _tBillAddress = _result.Object as TAddress;



            TAddress _tShipAddress = new TAddress();
            _result = _tBillAddress.getAddressById(_tOrder.ShipToAddressId);
            if (!_result.Success)
            {
                return(_result);
            }
            _tShipAddress = _result.Object as TAddress;


            TPaymentArrangement _tPaymentArrangement = new TPaymentArrangement();
            _result = _tPaymentArrangement.getPaymentArrangementList(orderId);
            if (!_result.Success)
            {
                return(_result);
            }
            EntityList _paymentList = _result.ObjectList;


            double _paymentApplied     = 0;
            double _estimatedAmountDue = 0;

            foreach (TPaymentArrangement _item in _paymentList)
            {
                if (_item.PayMethodId == 4)
                {
                    _estimatedAmountDue += _item.Amount;
                }
                else
                {
                    _paymentApplied += _item.Amount;
                }
            }



            #endregion


            try
            {
                #region setup EmailMessage

                EmailMessage _mail = new EmailMessage();

                string MailContent = HttpUtility.HtmlDecode(mi.FullHtml);

                #region filter the email content
                MailContent = MailContent.Replace("[CustomerName]", _tCustomer.FirstName == null ? "" : _tCustomer.FirstName.ToString());
                MailContent = MailContent.Replace("[OrderDate]", _tOrder.OrderDate.ToString("MM/dd/yyyy"));

                string siteURL = "http://admin.tecnifibreusa.com/";
                MailContent = MailContent.Replace("[WebSite]", siteURL);
                MailContent = MailContent.Replace("[OrderNumber]", _tOrder.AltOrderNum);
                MailContent = MailContent.Replace("[PONumber]", _tOrder.PONumber);
                MailContent = MailContent.Replace("[CustomerAcct]", _tCustomer.AltCustNum);
                MailContent = MailContent.Replace("[ShipMethod]", _tShipMethod.Description);

                MailContent = MailContent.Replace("[BillingAddress]", _tBillAddress.Company + "<br> " + _tBillAddress.Address1 + " " + _tBillAddress.Address2 + "<br>" + _tBillAddress.City + ", " + _tBillAddress.StateCode + " " + _tBillAddress.PostalCode);
                MailContent = MailContent.Replace("[ShippingAddress]", _tShipAddress.Company + "<br> " + _tShipAddress.Address1 + " " + _tShipAddress.Address2 + "<br>" + _tShipAddress.City + ", " + _tShipAddress.StateCode + " " + _tShipAddress.PostalCode);

                MailContent = MailContent.Replace("[SubTotal]", (_tOrder.TotalWholeSaleAmount - _tOrder.CompProductAmount).ToString("C", Utilities.CurrentNumberFormat));
                MailContent = MailContent.Replace("[Tax]", "(" + Utilities.Round(_tOrder.TaxRate * 100, 2).ToString() + "%)" + (_tOrder.TotalTax - _tOrder.CompTax).ToString("C", Utilities.CurrentNumberFormat));
                MailContent = MailContent.Replace("[Shipping]", (_tOrder.TotalShipping - _tOrder.CompShipingCost).ToString("C", Utilities.CurrentNumberFormat));
                MailContent = MailContent.Replace("[Discount]", (_tOrder.TotalDiscountAmount + _tOrder.CompProductAmount).ToString("C", Utilities.CurrentNumberFormat));
                MailContent = MailContent.Replace("[OrderTotal]", _tOrder.TotalOrderAmount.ToString("C", Utilities.CurrentNumberFormat));

                MailContent = MailContent.Replace("[PaymentApplied]", _paymentApplied.ToString("C", Utilities.CurrentNumberFormat));
                MailContent = MailContent.Replace("[EstimatedAmountDue]", _estimatedAmountDue.ToString("C", Utilities.CurrentNumberFormat));

                MailContent = MailContent.Replace("[BFirstName]", _tBillAddress.FirstName);
                MailContent = MailContent.Replace("[BLastName]", _tBillAddress.LastName);
                MailContent = MailContent.Replace("[SFirstName]", _tShipAddress.FirstName);
                MailContent = MailContent.Replace("[SLastName]", _tShipAddress.LastName);


                StringBuilder OrderItemHTML = new StringBuilder();

                foreach (TOrder_Line_Item _item in _list)
                {
                    OrderItemHTML.Append("<tr>");
                    OrderItemHTML.Append("  <td>" + _item.LineNum + "</td>");
                    OrderItemHTML.Append("<td>" + _item.PartNumber + "</td>");
                    OrderItemHTML.Append("<td>" + _item.ProductName + "</td>");
                    OrderItemHTML.Append("<td>" + _item.Quantity + "</td>");
                    if (_item.ShippedDate != null)
                    {
                        OrderItemHTML.Append("<td>" + _item.ShippedDate.Value.ToString("MM/dd/yyyy") + "</td>");
                    }
                    else
                    {
                        OrderItemHTML.Append("<td></td>");
                    }
                    OrderItemHTML.Append("<td>" + _item.TrackingNumber + "</td>");
                    OrderItemHTML.Append("<td>" + _item.Price.ToString("C", Utilities.CurrentNumberFormat) + "</td>");
                    OrderItemHTML.Append("<td>" + (_item.DiscountAmount + _item.ComAmount).ToString("C", Utilities.CurrentNumberFormat) + "</td>");
                    OrderItemHTML.Append("<td>" + ((_item.ActualPrice - _item.ComAmount) / _item.Quantity).ToString("C", Utilities.CurrentNumberFormat) + "</td>");
                    OrderItemHTML.Append("<td>" + (_item.ActualPrice - _item.ComAmount).ToString("C", Utilities.CurrentNumberFormat) + "</td>");
                    OrderItemHTML.Append("</tr>");
                }
                #endregion


                MailContent = MailContent.Replace("[Items]", OrderItemHTML.ToString());


                _mail.HtmlPart = new HtmlAttachment(MailContent);


                _mail.FromAddress = new EmailAddress(mi.RespondTo);
                _mail.Subject     = mi.Subject;

                if (Common.IsTest == true)
                {
                    string[] maillist = Common.TestMailTo.Split(';');
                    foreach (string _item in maillist)
                    {
                        _mail.AddToAddress(new EmailAddress(_item));
                    }

                    _result.Table = Common.TestMailTo;
                }
                else
                {
                    if (string.IsNullOrEmpty(_tCustomer.Email) == true)
                    {
                        _result.Success    = false;
                        _result.ErrMessage = "Email To Address is empty";
                        return(_result);
                    }
                    else
                    {
                        _mail.AddToAddress(new EmailAddress(_tCustomer.Email));
                    }

                    _result.Table = _tCustomer.Email;
                }


                if (string.IsNullOrEmpty(mi.BccAddress) == false)
                {
                    string[] bcclist = mi.BccAddress.Split(';');
                    foreach (string _item in bcclist)
                    {
                        if (string.IsNullOrEmpty(_item) == false)
                        {
                            _mail.AddBccAddress(new EmailAddress(_item));
                        }
                    }
                }
                if (string.IsNullOrEmpty(mi.CCAddress) == false)
                {
                    string[] bcclist = mi.CCAddress.Split(';');
                    foreach (string _item in bcclist)
                    {
                        if (string.IsNullOrEmpty(_item) == false)
                        {
                            _mail.AddCcAddress(new EmailAddress(_item));
                        }
                    }
                }


                if (string.IsNullOrEmpty(_tCustomer.OrderEmail) == false)
                {
                    _mail.AddCcAddress(new EmailAddress(_tCustomer.OrderEmail));
                }
                if (string.IsNullOrEmpty(_tCustomer.SecondaryEmail) == false)
                {
                    _mail.AddCcAddress(new EmailAddress(_tCustomer.SecondaryEmail));
                }

                if (string.IsNullOrEmpty(_tCustomer.SalesRepEmail) == false)
                {
                    _mail.AddBccAddress(new EmailAddress(_tCustomer.SalesRepEmail));
                }


                _result.ObjectValue = _mail;

                #endregion
            }
            catch (Exception ex)
            {
                _result.Success    = false;
                _result.ErrMessage = ex.ToString();
            }


            return(_result);
        }
示例#5
0
        public virtual ReturnValue GetMailContent(int orderId, int releaseID, TProgram_Email mi)
        {
            ReturnValue _result = new ReturnValue();

            System.Globalization.NumberFormatInfo nfi = Utilities.CurrentNumberFormat;

            #region getOrderInfo and Check

            TOrder _tOrder = new TOrder();
            _result = _tOrder.getOrderById(orderId);
            if (_result.Success == false)
            {
                return(_result);
            }

            _tOrder = _result.Object as TOrder;


            if (_tOrder.OrderId == 0)
            {
                _result.Success    = false;
                _result.ErrMessage = "the order doesn't exists --getOrderById";

                return(_result);
            }



            TOrder_Line_Item _tOrder_Line_Item = new TOrder_Line_Item();
            _result = _tOrder_Line_Item.getOrderDetailsByOrderId(orderId, releaseID);
            if (_result.Success == false)
            {
                return(_result);
            }

            EntityList _orderDetails = _result.ObjectList;


            if (_orderDetails.Count == 0)
            {
                _result.Success    = false;
                _result.ErrMessage = "the order doesn't exists---getOrdersDetail";

                return(_result);
            }


            #endregion

            try
            {
                #region generate Email Content

                EmailMessage _mail = new EmailMessage();

                #region Order Summary

                string MailContent = HttpUtility.HtmlDecode(mi.FullHtml);

                MailContent = MailContent
                              .Replace("{orderid}", _tOrder.AltOrderNum)
                              .Replace("{firstname}", _tOrder.FirstName)
                              .Replace("{shipmethod}", _tOrder.ShipMethodName)
                              .Replace("{ShipCarrier}", _tOrder.ShipCarrier)
                              .Replace("{CustomerName}", _tOrder.FirstName + " " + _tOrder.LastName)
                              .Replace("{trackingnumber}", _tOrder.TrackingNumber)
                              .Replace("{ShipDate}", _tOrder.ShippedDate.Value.ToString("MM/dd/yyyy"));

                #endregion

                TOrder_Line_Item _shipTo = _orderDetails[0] as TOrder_Line_Item;

                string shipinfo = _shipTo.ShipToAddress + "<br>" + _shipTo.ShipToCity + "," + _shipTo.ShipToState + " " + _shipTo.ShipToZip;

                MailContent = MailContent
                              .Replace("{shipmentnfo}", shipinfo);


                #region Shipping Detail

                string RepeatTemp = "";

                if (MailContent.IndexOf("{orderLine}") > 0)
                {
                    RepeatTemp = " <table  width =\"100%\" cellpadding=\"1\"><tr><td>SKU</td><td>Name</td><td>QTY</td></tr>";

                    foreach (TOrder_Line_Item _item in _orderDetails)
                    {
                        RepeatTemp = RepeatTemp + " <tr><td >" + _item.PartNumber + "</td><td>" + _item.ProductName +
                                     "</td><td>" + _item.Quantity.ToString() + "</td></tr>";
                    }

                    RepeatTemp = RepeatTemp + "</table>";
                }

                MailContent = MailContent.Replace("{orderLine}", RepeatTemp);

                #endregion



                #endregion

                _mail.HtmlPart = new HtmlAttachment(MailContent);

                #region setup EmailMessage

                _mail.FromAddress = new EmailAddress(mi.RespondTo);
                _mail.Subject     = mi.Subject.Replace("[Orderid]", _tOrder.AltOrderNum);

                if (Common.IsTest == true)
                {
                    string[] maillist = Common.TestMailTo.Split(';');
                    foreach (string _item in maillist)
                    {
                        _mail.AddToAddress(new EmailAddress(_item));
                    }

                    _result.Table = Common.TestMailTo;
                }
                else
                {
                    if (string.IsNullOrEmpty(_tOrder.Email) == true)
                    {
                        _result.Success    = false;
                        _result.ErrMessage = "Email To Address is empty";
                        return(_result);
                    }
                    else
                    {
                        string[] bcclist = _tOrder.Email.Split(';');
                        foreach (string _item in bcclist)
                        {
                            _mail.AddToAddress(new EmailAddress(_item));
                        }
                    }
                }

                if (string.IsNullOrEmpty(mi.BccAddress) == false)
                {
                    string[] bcclist = mi.BccAddress.Split(';');
                    foreach (string _item in bcclist)
                    {
                        _mail.AddBccAddress(new EmailAddress(_item));
                    }
                }
                if (string.IsNullOrEmpty(mi.CCAddress) == false)
                {
                    string[] bcclist = mi.CCAddress.Split(';');
                    foreach (string _item in bcclist)
                    {
                        _mail.AddCcAddress(new EmailAddress(_item));
                    }
                }

                #endregion

                _result.ObjectValue = _mail;
            }
            catch (Exception ex)
            {
                _result.Success    = false;
                _result.ErrMessage = ex.ToString();
            }



            return(_result);
        }
示例#6
0
        protected override ReturnValue customerEventPostShipmentUpdate(TOrder order, EntityList orderline, Transaction tran)
        {
            ReturnValue _result = new ReturnValue();

            #region Invoice

            #region get order

            TOrderTF _tOrder = new TOrderTF();
            _result = _tOrder.getOrderById(order.OrderId, tran);
            if (_result.Success == false)
            {
                return(_result);
            }
            _tOrder = _result.Object as TOrderTF;

            #endregion

            #region search invoice

            TInvoice _tInvoice = new TInvoice();
            _result = _tInvoice.getInvoice(order.OrderId, tran);
            if (_result.Success == false)
            {
                return(_result);
            }
            _tInvoice = _result.Object as TInvoice;

            #endregion

            if (_tInvoice.InvoiceId == 0)
            {
                #region Create new invoice

                TCustomer _tCustomer = new TCustomer();
                _result = _tCustomer.getCustomerById(_tOrder.PWPCustomerId);
                if (_result.Success == false)
                {
                    return(_result);
                }
                _tCustomer = _result.Object as TCustomer;

                TPaymentTerms _tPaymentTerms = new TPaymentTerms();
                _result = _tPaymentTerms.getPaymentTermsById(_tCustomer.PaymentTermsId);
                if (_result.Success == false)
                {
                    return(_result);
                }
                _tPaymentTerms = _result.Object as TPaymentTerms;

                TUser _tUser = new TUser();
                _result = _tUser.getUserById(_tCustomer.SalesRepId);
                if (_result.Success == false)
                {
                    return(_result);
                }
                _tUser = _result.Object as TUser;

                _tInvoice.InvoiceDate = System.DateTime.Now;
                _tInvoice.ShippedDate = order.ShippedDate.Value;
                _tInvoice.CreatedOn   = System.DateTime.Now;
                _tInvoice.OrderId     = order.OrderId;
                //_tInvoice.SessionId = _sessionId;
                _tInvoice.PONum         = _tOrder.PONumber;
                _tInvoice.CustomerId    = _tOrder.PWPCustomerId;
                _tInvoice.AltInvoiceNum = order.OrderId.ToString();

                _tInvoice.SalesRep = _tCustomer.SalesRepId;
                _tInvoice.Terms    = _tCustomer.PaymentTermsId;

                _tInvoice.TermsName    = _tPaymentTerms.Description;
                _tInvoice.SalesRepName = _tUser.SaleRepInitials;

                _tInvoice.DueDate       = System.DateTime.Now.AddDays(_tPaymentTerms.NetDueInDays);
                _tInvoice.PaymentStatus = "PEND";

                _result = _tInvoice.Save(tran);
                if (_result.Success == false)
                {
                    return(_result);
                }
                //_tInvoice.AltInvoiceNum = _orderId.ToString();
                _tInvoice.InvoiceId = _result.IdentityId;
                _tInvoice.QBRef     = _tInvoice.InvoiceId.ToString();
                _result             = _tInvoice.Update(tran);
                if (_result.Success == false)
                {
                    return(_result);
                }


                //_invoiceList.Add(_tInvoice);

                #endregion
            }

            #region invoice line

            foreach (TOrder_Line_Item item in orderline)
            {
                _result = item.getOrderLineByOrderPartNumber(order.OrderId, item.PartNumber, item.Quantity, tran);
                if (_result.Success == false)
                {
                    return(_result);
                }
                TOrder_Line_Item _tOrder_Line_Item = _result.Object as TOrder_Line_Item;

                if (_tOrder_Line_Item.ShippedDate == null || _tOrder_Line_Item.Quantity == 0 || item.Quantity == 0)
                {
                    continue;
                }

                TInvoice_Line_Item _tInvoice_Line_Item = new TInvoice_Line_Item();
                _tInvoice_Line_Item.InvoiceId        = _tInvoice.InvoiceId;
                _tInvoice_Line_Item.LineNum          = _tOrder_Line_Item.LineNum;
                _tInvoice_Line_Item.ProgramProductId = _tOrder_Line_Item.ProgramProductId;
                _tInvoice_Line_Item.ProductName      = _tOrder_Line_Item.ProductName;
                _tInvoice_Line_Item.PartNumber       = _tOrder_Line_Item.PartNumber;
                _tInvoice_Line_Item.Quantity         = item.Quantity;
                _tInvoice_Line_Item.ShippedDate      = _tOrder_Line_Item.ShippedDate.Value;
                _tInvoice_Line_Item.TrackingNumber   = _tOrder_Line_Item.TrackingNumber;
                _tInvoice_Line_Item.ReleaseNumber    = _tOrder_Line_Item.ReleaseNumber.Value;

                _tInvoice_Line_Item.OrderLineItemId = _tOrder_Line_Item.OrderLineItemId;
                _tInvoice_Line_Item.Amount          = (_tOrder_Line_Item.ActualPrice - _tOrder_Line_Item.ComAmount) * (item.Quantity / _tOrder_Line_Item.Quantity);
                _tInvoice_Line_Item.Price           = _tInvoice_Line_Item.Amount / item.Quantity;
                _result = _tInvoice_Line_Item.Save(tran);
                if (_result.Success == false)
                {
                    return(_result);
                }
            }

            #endregion

            #region update paid amount & invocie status

            TPaymentArrangement _tPaymentArrangement = new TPaymentArrangement();
            _result = _tPaymentArrangement.getTFOrderPaymentArrangementList(order.OrderId);
            if (_result.Success == false)
            {
                return(_result);
            }
            EntityList _payList = _result.ObjectList;


            double _paiedAmount = 0.00;

            bool _noPT = true;

            foreach (TPaymentArrangement _pItem in _payList)
            {
                if (_pItem.PayMethodId != 4)
                {
                    _paiedAmount += _pItem.Amount;
                }
                else
                {
                    _noPT = false;
                }
            }


            TInvoice_Line_Item _Invoice_Line_Item = new TInvoice_Line_Item();
            _result = _Invoice_Line_Item.getTotalInvoiceLineItemByInvoiceId(_tInvoice.InvoiceId, tran);
            if (_result.Success == false)
            {
                return(_result);
            }
            _Invoice_Line_Item = _result.Object as TInvoice_Line_Item;

            if ((_tOrder.TotalWholeSaleAmount - _tOrder.CompProductAmount) != 0)
            {
                Double _productAmountRate = _Invoice_Line_Item.Amount / (_tOrder.TotalWholeSaleAmount - _tOrder.CompProductAmount);

                _tInvoice.Subtotal      = WComm.Utilities.Round(_Invoice_Line_Item.Amount, 2);
                _tInvoice.Shipping      = WComm.Utilities.Round(_productAmountRate * (_tOrder.TotalShipping - _tOrder.CompShipingCost), 2);
                _tInvoice.Tax           = WComm.Utilities.Round(_productAmountRate * (_tOrder.TotalTax - _tOrder.CompTax), 2);
                _tInvoice.InvoiceAmount = WComm.Utilities.Round(_tInvoice.Subtotal + _tInvoice.Shipping + _tInvoice.Tax, 2);
                _tInvoice.PaiedAmount   = WComm.Utilities.Round(_paiedAmount * _productAmountRate, 2);
                _tInvoice.BalanceDue    = WComm.Utilities.Round(_tInvoice.InvoiceAmount - _tInvoice.PaiedAmount, 2);
                if (_noPT == true)
                {
                    _tInvoice.PaymentStatus = "PAID";
                    _tInvoice.BalanceDue    = 0;
                    _tInvoice.PaiedAmount   = _tInvoice.InvoiceAmount;
                }
                _result = _tInvoice.Update(tran);
                if (_result.Success == false)
                {
                    return(_result);
                }
            }

            #endregion

            #region sent invoice email

            VCBusiness.TecnifibreEmailFactory EmailFactory = new TecnifibreEmailFactory();

            _result = EmailFactory.SentInvoiceEmail(_tInvoice.InvoiceId);
            if (_result.Success == false)
            {
                return(_result);
            }


            _tInvoice.EmailSentOn = System.DateTime.Now;
            _result = _tInvoice.Update(tran);
            if (_result.Success == false)
            {
                return(_result);
            }

            #endregion


            #endregion

            return(_result);
        }
示例#7
0
文件: Order.cs 项目: QYFS2018/VC2
        public override ReturnValue UpdateShipment()
        {
            ReturnValue _result = new ReturnValue();

            Common.Connect();

            #region get order list

            TOrder _tOrder = new TOrder();
            _result = _tOrder.getShimentOrderList();
            if (_result.Success == false)
            {
                _result.Success    = false;
                _result.ErrMessage = "getShimentOrderList failed. \r\n " + _result.ErrMessage;

                Common.Log("getShimentOrderList---ER \r\n" + _result.ErrMessage);

                return(_result);
            }

            EntityList orderList = _result.ObjectList;

            VCBusiness.Model.TProgram_Email _tProgram_Email = Common.CreateObject(this.Owner, "TProgram_Email") as VCBusiness.Model.TProgram_Email;
            _result = _tProgram_Email.getEmailTemplate("SHIP_CONFIRMATION");
            if (_result.Success == false)
            {
                _result.Success    = false;
                _result.ErrMessage = "getEmailTemplate failed. \r\n " + _result.ErrMessage;

                Common.Log("getEmailTemplate---ER \r\n" + _result.ErrMessage);

                return(_result);
            }

            _tProgram_Email = _result.Object as TProgram_Email;



            #endregion

            #region update shipment

            foreach (TOrder order in orderList)
            {
                Common.Log("Order : " + order.OrderId);

                #region GetOrderShipmentInfo

                EntityList productList = new EntityList();

                if (Convert.ToBoolean(System.Configuration.ConfigurationSettings.AppSettings["IsTestMode"].ToString()) == true)
                {
                    #region test


                    TOrder_Line_Item orderline = new TOrder_Line_Item();
                    _result = orderline.getOrderLineItemsByOrderId(order.OrderId);

                    foreach (TOrder_Line_Item item in _result.ObjectList)
                    {
                        item.ShipCarrier    = "UPS";
                        item.ShipMethod     = "STD";
                        item.TrackingNumber = "123456789";
                        item.ShippedDate    = System.DateTime.Now;
                        productList.Add(item);
                    }

                    #endregion
                }
                else
                {
                    #region call Veracore

                    _result = VeraCore.GetOrderShipmentInfo(order.OrderId.ToString());
                    if (_result.Success == false)
                    {
                        if (_result.ErrMessage.IndexOf("Invalid Order ID") > -1)
                        {
                            _result.ErrMessage = "Can't find the order";
                        }
                        else
                        {
                            errorNotes = errorNotes + order.OrderId.ToString() + "\r\n" + _result.ErrMessage + "\r\n";
                            failedRecord++;
                        }
                        Common.Log("Order : " + order.OrderId + "  GetOrderShipmentInfo---ER \r\n" + _result.ErrMessage);

                        continue;
                    }

                    productList = _result.ObjectList;

                    if (productList.Count() == 0)
                    {
                        Common.Log("Order : " + order.OrderId + "---Unshipped");

                        continue;
                    }

                    #endregion
                }

                #endregion

                Transaction _tran = new Transaction();

                #region update order line



                foreach (TOrder_Line_Item item in productList)
                {
                    order.ShipCarrier    = item.ShipCarrier;
                    order.ShipMethod     = item.ShipMethod;
                    order.TrackingNumber = item.TrackingNumber;
                    order.ShippedDate    = item.ShippedDate.Value;

                    _result = item.updateOrderLineItemShipment(order.OrderId, item.PartNumber, item.ShippedDate.Value, item.TrackingNumber, _tran);
                    if (_result.Success == false)
                    {
                        _tran.RollbackTransaction();
                        errorNotes = errorNotes + order.OrderId.ToString() + "\r\n" + _result.ErrMessage + "\r\n";
                        failedRecord++;

                        Common.Log("Order : " + order.OrderId + "  updateOrderLineItemShipment---ER \r\n" + _result.ErrMessage);

                        continue;
                    }

                    if (this.Owner.OwnerInfo["ImportDM"].ToString() == "Y")
                    {
                        TDM_Order_Detail _tDM_Order_Detail = new TDM_Order_Detail();
                        _tDM_Order_Detail.DataConnectProviders = "ZoytoPH";
                        _result = _tDM_Order_Detail.updateDMShipingInfo(order.OrderId, item.PartNumber, order.ShippedDate.Value, order.TrackingNumber);
                        if (_result.Success == false)
                        {
                            _tran.RollbackTransaction();
                            errorNotes = errorNotes + order.OrderId.ToString() + "\r\n" + _result.ErrMessage + "\r\n";
                            failedRecord++;

                            Common.Log("Order : " + order.OrderId + "  updateDMShipingInfo---ER \r\n" + _result.ErrMessage);

                            continue;
                        }
                    }
                }

                #endregion

                #region update carton & ASN

                #region get release list

                TOrder_Line_Item _tOrder_Line_Item = new TOrder_Line_Item();
                _result = _tOrder_Line_Item.getOrderReleaseByOrderId(order.OrderId, _tran);
                if (_result.Success == false)
                {
                    _tran.RollbackTransaction();
                    errorNotes = errorNotes + order.OrderId.ToString() + "\r\n" + _result.ErrMessage + "\r\n";
                    failedRecord++;

                    Common.Log("Order : " + order.OrderId + "  getOrderReleaseByOrderId---ER \r\n" + _result.ErrMessage);

                    continue;
                }

                EntityList _releaseList = _result.ObjectList;

                #endregion

                #region delete cartion and ASN

                TOrder_Line_Shipment_Carton _tOrder_Line_Shipment_Carton = new TOrder_Line_Shipment_Carton();
                _result = _tOrder_Line_Shipment_Carton.deleteOrderLineShipmentCartonByOrderID(order.OrderId, _tran);
                if (_result.Success == false)
                {
                    _tran.RollbackTransaction();
                    errorNotes = errorNotes + order.OrderId.ToString() + "\r\n" + _result.ErrMessage + "\r\n";
                    failedRecord++;

                    Common.Log("Order : " + order.OrderId + "  deleteOrderLineShipmentCartonByOrderID---ER \r\n" + _result.ErrMessage);

                    continue;
                }


                TOrder_Line_Shipment_ASN _tOrder_Line_Shipment_ASN = new TOrder_Line_Shipment_ASN();
                _result = _tOrder_Line_Shipment_ASN.deleteOrderLineShipmentASNByOrderID(order.OrderId, _tran);
                if (_result.Success == false)
                {
                    _tran.RollbackTransaction();
                    errorNotes = errorNotes + order.OrderId.ToString() + "\r\n" + _result.ErrMessage + "\r\n";
                    failedRecord++;

                    Common.Log("Order : " + order.OrderId + "  deleteOrderLineShipmentASNByOrderID---ER \r\n" + _result.ErrMessage);

                    continue;
                }

                #endregion

                int releaseID = 1;
                foreach (TOrder_Line_Item item in _releaseList)
                {
                    #region update release number && carton && ASN

                    _result = item.updateOrderReleaseByTracking(order.OrderId, item.TrackingNumber, releaseID, _tran);
                    if (_result.Success == false)
                    {
                        _tran.RollbackTransaction();
                        errorNotes = errorNotes + order.OrderId.ToString() + "\r\n" + _result.ErrMessage + "\r\n";
                        failedRecord++;

                        Common.Log("Order : " + order.OrderId + "  updateOrderReleaseByTracking---ER \r\n" + _result.ErrMessage);

                        continue;
                    }

                    _tOrder_Line_Shipment_Carton                  = new TOrder_Line_Shipment_Carton();
                    _tOrder_Line_Shipment_Carton.ORDER_ID         = order.OrderId;
                    _tOrder_Line_Shipment_Carton.RELEASE_NUM      = releaseID;
                    _tOrder_Line_Shipment_Carton.CARTON_ID_FROM   = releaseID.ToString();
                    _tOrder_Line_Shipment_Carton.CARRIER_ID       = order.ShipCarrier;
                    _tOrder_Line_Shipment_Carton.SHIP_METHOD      = order.ShipMethod;
                    _tOrder_Line_Shipment_Carton.PACKAGE_TRACE_ID = item.TrackingNumber;
                    _tOrder_Line_Shipment_Carton.Ship_date        = item.ShippedDate.Value;

                    _result = _tOrder_Line_Shipment_Carton.Save(_tran);
                    if (_result.Success == false)
                    {
                        _tran.RollbackTransaction();
                        errorNotes = errorNotes + order.OrderId.ToString() + "\r\n" + _result.ErrMessage + "\r\n";
                        failedRecord++;

                        Common.Log("Order : " + order.OrderId + "  _tOrder_Line_Shipment_Carton.Save---ER \r\n" + _result.ErrMessage);

                        continue;
                    }


                    _result = item.createASN(order.OrderId, releaseID, _tran);
                    if (_result.Success == false)
                    {
                        _tran.RollbackTransaction();
                        errorNotes = errorNotes + order.OrderId.ToString() + "\r\n" + _result.ErrMessage + "\r\n";
                        failedRecord++;

                        Common.Log("Order : " + order.OrderId + " createASN---ER \r\n" + _result.ErrMessage);

                        continue;
                    }

                    #endregion

                    releaseID++;
                }

                #endregion

                #region update phontom item

                _result = _tOrder.updateOrderPhontomOrderStatus(order.OrderId, order.ShippedDate.Value, order.TrackingNumber, _tran);
                if (_result.Success == false)
                {
                    _tran.RollbackTransaction();
                    errorNotes = errorNotes + order.OrderId.ToString() + "\r\n" + _result.ErrMessage + "\r\n";
                    failedRecord++;

                    Common.Log("Order : " + order.OrderId + "  updateOrderPhontomOrderStatus---ER \r\n" + _result.ErrMessage);

                    continue;
                }

                #endregion

                #region customerEventPostShipmentUpdate

                _result = this.customerEventPostShipmentUpdate(order, productList, _tran);
                if (_result.Success == false)
                {
                    _tran.RollbackTransaction();
                    errorNotes = errorNotes + order.OrderId.ToString() + "\r\n" + _result.ErrMessage + "\r\n";
                    failedRecord++;

                    Common.Log("Order : " + order.OrderId + "  customerEventPostShipmentUpdate---ER \r\n" + _result.ErrMessage);

                    continue;
                }



                #endregion

                _tran.CommitTransaction();

                #region sent confirm email

                if (Owner.OwnerInfo["ShipConfirmation"].ToString() == "Y")
                {
                    #region check already sent email

                    App_Log_Mail _app_Log_Mail = new App_Log_Mail();
                    _result = _app_Log_Mail.getEmailLog(order.OrderId, releaseID - 1);
                    if (_result.Success == false)
                    {
                        errorNotes = errorNotes + order.OrderId.ToString() + "\r\n" + _result.ErrMessage + "\r\n";
                        failedRecord++;

                        Common.Log("Order : " + order.OrderId + "  getEmailLog---ER \r\n" + _result.ErrMessage);

                        continue;
                    }
                    _app_Log_Mail = _result.Object as App_Log_Mail;

                    #endregion

                    if (_app_Log_Mail.ID == 0)
                    {
                        #region sent shipment email

                        #region get email content

                        VCBusiness.EmailFactory EmailFactory = Common.CreateObject(this.Owner, "EmailFactory") as VCBusiness.EmailFactory;
                        _result = EmailFactory.GetMailContent(order.OrderId, releaseID - 1, _tProgram_Email);
                        if (_result.Success == false)
                        {
                            errorNotes = errorNotes + order.OrderId.ToString() + "\r\n" + _result.ErrMessage + "\r\n";
                            failedRecord++;

                            Common.Log("Order : " + order.OrderId + "  GetMailContent---ER \r\n" + _result.ErrMessage);

                            continue;
                        }
                        EmailMessage email = _result.ObjectValue as EmailMessage;

                        #endregion

                        #region sent email

                        _result = EmailFactory.SentEmail(order.OrderId, releaseID - 1, email);
                        if (_result.Success == false)
                        {
                            errorNotes = errorNotes + order.OrderId.ToString() + "\r\n" + _result.ErrMessage + "\r\n";
                            failedRecord++;

                            Common.Log("Order : " + order.OrderId + "  SentEmail---ER \r\n" + _result.ErrMessage);

                            continue;
                        }
                        #endregion

                        #endregion
                    }
                }

                #endregion

                successfulRecord++;
                Common.Log("Order : " + order.OrderId + "---OK");
            }

            #endregion

            #region update Order Status SH

            _result = _tOrder.updateOrderStatusSH();
            if (_result.Success == false)
            {
                _result.Success    = false;
                _result.ErrMessage = "updateOrderStatusSH failed. \r\n " + _result.ErrMessage;

                Common.Log("updateOrderStatusSH---ER \r\n" + _result.ErrMessage);

                return(_result);
            }


            #endregion

            Common.SentAlterEmail(failedRecord, errorNotes);

            _result.Success = true;


            return(_result);
        }