Beispiel #1
0
        public static bool GetShippingRate(ref Hashtable Head)
        {
            ///   shippingrate sr = new shippingrate();
            shippingrate target = new shippingrate(); // TODO: Initialize to an appropriate value

            target.Timeout = 10000;                   //设置10秒 , 提高反应速度
            // target.Url = "   http://buyqa.advantech.com:9000/services/shippingrate.asmx";
            Order order = new Order();                // TODO: Initialize to an appropriate value

            order.StoreId = Head["StoreId"].ToString();
            Address shipto = new Address();

            shipto.Countrycode = Head["shiptoCountrycode"].ToString();
            shipto.Zipcode     = Head["shiptoZipcode"].ToString();
            shipto.StateCode   = Head["shiptoStateCode"].ToString();
            Address billto = new Address();

            billto.Countrycode = Head["billtoCountrycode"].ToString();
            billto.StateCode   = Head["billtoStateCode"].ToString();
            billto.Zipcode     = Head["billtoZipcode"].ToString();
            order.Shipto       = shipto;
            order.Billto       = billto;
            DataTable dt = (DataTable)Head["items"];

            List <Item> items = new List <Item>();

            DataRow[] drs = dt.Select(string.Format("type={0}", 0));
            if (drs.Length > 0)
            {
                for (int i = 0; i <= drs.Length - 1; i++)
                {
                    items.Add(new Item()
                    {
                        ProductID = drs[i]["partno"].ToString(), Qty = Convert.ToInt32(drs[i]["Qty"])
                    });
                }
            }

            List <ConfigSystem> systems = new List <ConfigSystem>();

            DataRow[] drsP = dt.Select(string.Format("type={0}", -1));
            for (int i = 0; i <= drsP.Length - 1; i++)
            {
                int          _sys1Qty = 1;
                ConfigSystem _sys1    = new ConfigSystem();
                _sys1.Qty       = Convert.ToInt32(drsP[i]["Qty"]);
                _sys1.ProductID = drsP[i]["partno"].ToString();
                _sys1Qty        = _sys1.Qty;

                DataRow[]   drsC = dt.Select(string.Format("type={0} and HigherLevel ={1}", 1, drsP[i]["lineno"]));
                List <Item> _ds  = new List <Item>();
                for (int j = 0; j <= drsC.Length - 1; j++)
                {
                    _ds.Add(new Item()
                    {
                        ProductID = drsC[j]["partno"].ToString(),
                        Qty       = (Int32)Math.Ceiling((double)(Convert.ToDouble(drsC[j]["Qty"]) / (double)_sys1Qty))
                    });
                }
                _sys1.Details = _ds.ToArray();
                systems.Add(_sys1);
            }



            order.Items   = items.ToArray();
            order.Systems = systems.ToArray();
            Response actual;

            actual = target.getShippingRate(order);

            if (actual != null && actual.Status == "1")
            {
                //List <string,string>  = new     List()<string,string>;
                DataTable shipdt = new DataTable();
                shipdt.Columns.Add("name", typeof(string));
                shipdt.Columns.Add("freight", typeof(float));
                shipdt.Columns.Add("TextStr", typeof(string));
                //   Dictionary<string, float> shiplist = new Dictionary<string, float>();

                foreach (ShippingRate _ShippingRate in actual.ShippingRates)
                {
                    DataRow dr = shipdt.NewRow();
                    dr["name"]    = _ShippingRate.Nmae;
                    dr["freight"] = _ShippingRate.Rate;
                    dr["TextStr"] = String.Format("{0}  ({1})", dr["name"], dr["freight"]);
                    //   shiplist[_ShippingRate.Nmae] = _ShippingRate.Rate;
                    shipdt.Rows.Add(dr);
                }
                shipdt.AcceptChanges();
                Head["ShippingRates"] = shipdt;
                //foreach (var item in xxx.Keys)
                //{
                //    string name = item;
                //    string value = xxx[item];
                //}
                // ShipList = actual.ShippingRates;
                //this.GridView1.DataSource = actual.ShippingRates;
                //this.GridView1.DataBind();
                //this.rpPackingBox.DataSource = actual.Boxex;
                //this.rpPackingBox.DataBind();
                return(true);
            }
            // ShipList = null;
            return(false);
        }
Beispiel #2
0
        /// <summary>
        /// Use eStore B+B function to calcaulate freight
        /// </summary>
        /// <returns></returns>
        public static Tuple <bool, Response> CalculateBBFreight(SAP_DIMCOMPANY _Soldto, SAP_DIMCOMPANY _Shipto, SAP_DIMCOMPANY _Billto, List <cart_DETAIL_V2> _CartItems)
        {
            shippingrate target = new shippingrate();

            target.Timeout = 30000;
            //target.Url = "http://buy.advantech.com/services/shippingrate.asmx"; AUS eStore URL

            DataAccess.bbeStoreFreightAPI.Order order = new DataAccess.bbeStoreFreightAPI.Order();
            order.StoreId = "ABB";

            // Shipto settings
            Address shipto = new Address();

            if (_Shipto != null)
            {
                shipto.Countrycode = _Shipto.COUNTRY;
                shipto.Zipcode     = _Shipto.ZIP_CODE;
                shipto.StateCode   = _Shipto.REGION_CODE;
                order.Shipto       = shipto;
            }

            // Bill to settings
            Address billto = new Address();

            if (_Billto != null)
            {
                billto.Countrycode = _Billto.COUNTRY;
                billto.Zipcode     = _Billto.ZIP_CODE;
                billto.StateCode   = _Billto.REGION_CODE;
                order.Billto       = billto;
            }

            // Loose Items settings
            List <Item>           items      = new List <Item>();
            List <cart_DETAIL_V2> LooseItems = _CartItems.Where(d => d.otype == 0).ToList();

            if (LooseItems.Count > 0)
            {
                foreach (cart_DETAIL_V2 LooseItem in LooseItems)
                {
                    items.Add(new Item()
                    {
                        ProductID = LooseItem.Part_No,
                        Qty       = (int)LooseItem.Qty
                    });
                }
            }

            // System Items settings
            List <ConfigSystem>   systems     = new List <ConfigSystem>();
            List <cart_DETAIL_V2> ParentItems = _CartItems.Where(d => d.otype == -1).ToList();

            foreach (cart_DETAIL_V2 ParentItem in ParentItems)
            {
                int          _sys1Qty = 1;
                ConfigSystem _sys1    = new ConfigSystem();
                _sys1.Qty       = (int)ParentItem.Qty;
                _sys1.ProductID = ParentItem.Part_No;
                _sys1Qty        = _sys1.Qty;

                List <cart_DETAIL_V2> ChildItems = _CartItems.Where(d => d.otype == 1 && d.higherLevel == ParentItem.Line_No).ToList();
                List <Item>           _ds        = new List <Item>();
                foreach (cart_DETAIL_V2 ChildItem in ChildItems)
                {
                    _ds.Add(new Item()
                    {
                        ProductID = ChildItem.Part_No,
                        Qty       = (Int32)Math.Ceiling((double)(Convert.ToDouble(ChildItem.Qty / (double)_sys1Qty)))
                    });
                }

                _sys1.Details = _ds.ToArray();
                systems.Add(_sys1);
            }
            order.Items   = items.ToArray();
            order.Systems = systems.ToArray();



            Response actual;

            actual = target.getShippingRate(order);
            if (actual != null && actual.Status == "1")
            {
                return(new Tuple <bool, Response>(true, actual));
            }
            else
            {
                return(new Tuple <bool, Response>(false, actual));
            }
        }
Beispiel #3
0
        /// <summary>
        /// Use eStore B+B function to calcaulate freight
        /// </summary>
        /// <returns></returns>
        public static Tuple <bool, Response> CalculateBBFreightByQuotationDetail(EQPARTNER _Shipto, EQPARTNER _Billto, List <QuotationDetail> _QuoteDetails)
        {
            shippingrate target = new shippingrate();

            target.Timeout = 30000;
            //target.Url = "http://buy.advantech.com/services/shippingrate.asmx"; AUS eStore URL

            DataAccess.bbeStoreFreightAPI.Order order = new DataAccess.bbeStoreFreightAPI.Order();
            order.StoreId = "ABB";

            // Shipto settings
            Address shipto = new Address();

            if (_Shipto != null)
            {
                shipto.Countrycode = _Shipto.COUNTRY;
                shipto.Zipcode     = _Shipto.ZIPCODE;
                shipto.StateCode   = _Shipto.STATE;
                order.Shipto       = shipto;
            }

            // Bill to settings
            Address billto = new Address();

            if (_Billto != null)
            {
                billto.Countrycode = _Billto.COUNTRY;
                billto.Zipcode     = _Billto.ZIPCODE;
                billto.StateCode   = _Billto.STATE;
                order.Billto       = billto;
            }

            // Loose Items settings
            List <Item>            items      = new List <Item>();
            List <QuotationDetail> LooseItems = _QuoteDetails.Where(q => q.ItemType == (int)LineItemType.LooseItem).ToList();

            if (LooseItems.Count > 0)
            {
                foreach (QuotationDetail LooseItem in LooseItems)
                {
                    items.Add(new Item()
                    {
                        ProductID = LooseItem.partNo,
                        Qty       = (int)LooseItem.qty
                    });
                }
            }

            // System Items settings
            List <ConfigSystem>    systems     = new List <ConfigSystem>();
            List <QuotationDetail> ParentItems = _QuoteDetails.Where(q => q.ItemType == (int)LineItemType.BTOSParent).ToList();

            foreach (QuotationDetail ParentItem in ParentItems)
            {
                int          _sys1Qty = 1;
                ConfigSystem _sys1    = new ConfigSystem();
                _sys1.Qty       = (int)ParentItem.qty;
                _sys1.ProductID = ParentItem.partNo;
                _sys1Qty        = _sys1.Qty;

                List <QuotationDetail> ChildItems = _QuoteDetails.Where(q => q.ItemType == (int)LineItemType.BTOSChild && q.HigherLevel == ParentItem.line_No).ToList();
                List <Item>            _ds        = new List <Item>();
                foreach (QuotationDetail ChildItem in ChildItems)
                {
                    _ds.Add(new Item()
                    {
                        ProductID = ChildItem.partNo,
                        Qty       = (Int32)Math.Ceiling((double)(Convert.ToDouble(ChildItem.qty / (double)_sys1Qty)))
                    });
                }

                _sys1.Details = _ds.ToArray();
                systems.Add(_sys1);
            }
            order.Items   = items.ToArray();
            order.Systems = systems.ToArray();



            Response actual;

            actual = target.getShippingRate(order);
            if (actual != null && actual.Status == "1")
            {
                return(new Tuple <bool, Response>(true, actual));
            }
            else
            {
                return(new Tuple <bool, Response>(false, actual));
            }
        }
Beispiel #4
0
        /// <summary>
        /// Use eStore B+B function to calcaulate freight(simple version for ajax)
        /// </summary>
        /// <returns></returns>
        public static ShippingResult CalculateBBFreight(string shipToCountry, string shipToZipCode, string shipToState, string cartId, WebSource source = WebSource.Myadvantech)
        {
            ShippingResult        shippingResult  = new ShippingResult();
            List <ShippingMethod> shippingmethods = new List <ShippingMethod>();
            Response response;

            try
            {
                List <FreightOption> freightOptions = Advantech.Myadvantech.DataAccess.MyAdvantechDAL.GetAllFreightOptions();
                foreach (var option in freightOptions)
                {
                    ShippingMethod method = new ShippingMethod();
                    method.MethodName          = option.SAPCode + ": " + option.Description;
                    method.MethodValue         = option.CarrierCode + ": " + option.Description;
                    method.DisplayShippingCost = "N/A";
                    method.ErrorMessage        = "";
                    if (option.EStoreServiceName != null)
                    {
                        method.EstoreServiceName = option.EStoreServiceName;
                    }
                    shippingmethods.Add(method);
                }


                try
                {
                    shippingrate target = new shippingrate();
                    target.Timeout = 30000;
                    //target.Url = "http://buy.advantech.com/services/shippingrate.asmx"; AUS eStore URL

                    DataAccess.bbeStoreFreightAPI.Order order = new DataAccess.bbeStoreFreightAPI.Order();
                    order.StoreId = "ABB";


                    // Shipto settings
                    Address shipto = new Address();
                    shipto.Countrycode = shipToCountry;
                    shipto.Zipcode     = shipToZipCode;
                    shipto.StateCode   = shipToState;
                    order.Shipto       = shipto;
                    order.Billto       = shipto;

                    if (source == WebSource.Myadvantech)
                    {
                        List <Advantech.Myadvantech.DataAccess.cart_DETAIL_V2> cartItems = Advantech.Myadvantech.DataAccess.CartDetailHelper.GetCartDetailByID(cartId);

                        // Loose Items settings
                        List <Item>           items      = new List <Item>();
                        List <cart_DETAIL_V2> LooseItems = cartItems.Where(d => d.otype == 0).ToList();
                        if (LooseItems.Count > 0)
                        {
                            foreach (cart_DETAIL_V2 LooseItem in LooseItems)
                            {
                                items.Add(new Item()
                                {
                                    ProductID = LooseItem.Part_No,
                                    Qty       = (int)LooseItem.Qty
                                });
                            }
                        }

                        // System Items settings
                        List <ConfigSystem>   systems     = new List <ConfigSystem>();
                        List <cart_DETAIL_V2> ParentItems = cartItems.Where(d => d.otype == -1).ToList();
                        foreach (cart_DETAIL_V2 ParentItem in ParentItems)
                        {
                            int          _sys1Qty = 1;
                            ConfigSystem _sys1    = new ConfigSystem();
                            _sys1.Qty       = (int)ParentItem.Qty;
                            _sys1.ProductID = ParentItem.Part_No;
                            _sys1Qty        = _sys1.Qty;

                            List <cart_DETAIL_V2> ChildItems = cartItems.Where(d => d.otype == 1 && d.higherLevel == ParentItem.Line_No).ToList();
                            List <Item>           _ds        = new List <Item>();
                            foreach (cart_DETAIL_V2 ChildItem in ChildItems)
                            {
                                _ds.Add(new Item()
                                {
                                    ProductID = ChildItem.Part_No,
                                    Qty       = (Int32)Math.Ceiling((double)(Convert.ToDouble(ChildItem.Qty / (double)_sys1Qty)))
                                });
                            }

                            _sys1.Details = _ds.ToArray();
                            systems.Add(_sys1);
                        }
                        order.Items   = items.ToArray();
                        order.Systems = systems.ToArray();
                    }
                    else if (source == WebSource.eQuotation)
                    {
                        var quotationMaster = QuoteBusinessLogic.GetQuotationMaster(cartId);
                        if (quotationMaster != null)
                        {
                            List <QuotationDetail> _QuoteDetails = quotationMaster.QuotationDetail;

                            // Loose Items settings
                            List <Item>            items      = new List <Item>();
                            List <QuotationDetail> LooseItems = _QuoteDetails.Where(q => q.ItemType == (int)LineItemType.LooseItem).ToList();
                            if (LooseItems.Count > 0)
                            {
                                foreach (QuotationDetail LooseItem in LooseItems)
                                {
                                    items.Add(new Item()
                                    {
                                        ProductID = LooseItem.partNo,
                                        Qty       = (int)LooseItem.qty
                                    });
                                }
                            }

                            // System Items settings
                            List <ConfigSystem>    systems     = new List <ConfigSystem>();
                            List <QuotationDetail> ParentItems = _QuoteDetails.Where(q => q.ItemType == (int)LineItemType.BTOSParent).ToList();
                            foreach (QuotationDetail ParentItem in ParentItems)
                            {
                                int          _sys1Qty = 1;
                                ConfigSystem _sys1    = new ConfigSystem();
                                _sys1.Qty       = (int)ParentItem.qty;
                                _sys1.ProductID = ParentItem.partNo;
                                _sys1Qty        = _sys1.Qty;

                                List <QuotationDetail> ChildItems = _QuoteDetails.Where(q => q.ItemType == (int)LineItemType.BTOSChild && q.HigherLevel == ParentItem.line_No).ToList();
                                List <Item>            _ds        = new List <Item>();
                                foreach (QuotationDetail ChildItem in ChildItems)
                                {
                                    _ds.Add(new Item()
                                    {
                                        ProductID = ChildItem.partNo,
                                        Qty       = (Int32)Math.Ceiling((double)(Convert.ToDouble(ChildItem.qty / (double)_sys1Qty)))
                                    });
                                }

                                _sys1.Details = _ds.ToArray();
                                systems.Add(_sys1);
                            }
                            order.Items   = items.ToArray();
                            order.Systems = systems.ToArray();
                        }
                    }



                    response = target.getShippingRate(order);
                }
                catch (Exception ex)
                {
                    throw ex;
                }



                if (response != null)
                {
                    if (response.ShippingRates != null)
                    {
                        var normalShippingRatesList = new List <ShippingRate>();
                        foreach (var item in response.ShippingRates)
                        {
                            foreach (var method in shippingmethods)
                            {
                                if (method.EstoreServiceName == item.Nmae)
                                {
                                    method.ShippingCost        = item.Rate;
                                    method.DisplayShippingCost = item.Rate.ToString();
                                    method.ErrorMessage        = string.IsNullOrEmpty(item.ErrorMessage)? "" : item.ErrorMessage;

                                    //配對成功的就移除
                                    normalShippingRatesList.Add(item);
                                }
                            }
                        }
                        var unnormalShippingRatesList = response.ShippingRates.Where(p => !normalShippingRatesList.Any(p2 => p2.Nmae == p.Nmae));
                        if (unnormalShippingRatesList.Any())
                        {
                            shippingResult.Message = string.Join("<br/>", unnormalShippingRatesList.Select(s => s.Nmae).ToList());
                        }
                    }

                    if (response.Boxex[0] != null)
                    {
                        shippingResult.Weight = (double)Decimal.Round(response.Boxex[0].Weight, 2);
                    }



                    shippingResult.Status = response.Status;
                    //if (response.DetailMessages != null)
                    //    shippingResult.DetailMessage += string.Join(",", response.DetailMessages);
                }
                else
                {
                    shippingResult.Message = "No Response. Please select one freight option and manually enter cost.";
                    shippingResult.Status  = "0";
                }
            }
            catch (Exception ex)
            {
                shippingResult.Message       = "Exception occurs. Please contact Myadvantech team.";
                shippingResult.DetailMessage = ex.Message;
                shippingResult.Status        = "0";
            }

            shippingResult.ShippingMethods = shippingmethods;


            return(shippingResult);
        }