예제 #1
0
파일: DLS.cs 프로젝트: alefurman40/api_2
        // This list is named dlsPricesheets, but works for either regular or AM or PM Guaranteed rates
        // which ever is passed as the ref parameter

        private void getRateFromDLS(ref List <dlsPricesheet> dlsPricesheets, ref bool guaranteedService)
        {
            #region Variables

            //string url = "", referrer, contentType, accept, method;

            string doc = "", data = "";
            //CookieContainer container = new CookieContainer();

            //url = "https://dlsworldwideproxy-stage.rrd.com/services";
            //url = "https://dlsworldwideproxy.rrd.com/services/api/v1/RateShop/RateRequest";

            //url = "https://dlsworldwideproxy.rrd.com/services/api/v1/RateShop/RateRequest";
            ////url = "https://dlsworldwideproxy-stage.rrd.com/services/api/v1/RateShop/RateRequest";
            //referrer = "";
            //contentType = "application/xml";
            //method = "POST";
            //accept = "text/xml";

            bool isOverlength    = HelperFuncs.IsOverlength(ref quoteData.m_lPiece, 192, 192, 192);
            bool isOverlengthUPS = HelperFuncs.IsOverlength(ref quoteData.m_lPiece, 92, 92, 92);

            #endregion

            try
            {
                StringBuilder accessorials = new StringBuilder();

                Get_accessorials_request_xml(guaranteedService, isOverlength, accessorials);

                #region Post Data

                #region Date

                DateTime today = quoteData.puDate;
                string   day   = today.Day.ToString();
                if (day.Length.Equals(1))
                {
                    day = string.Concat("0", day);
                }

                string month = today.Month.ToString();
                if (month.Length.Equals(1))
                {
                    month = string.Concat("0", month);
                }
                string year = today.Year.ToString();

                #endregion

                #region Weight/class/overlength

                Int16 length, width, height;

                StringBuilder sbiItems = new StringBuilder();
                string        fClass   = "";
                double        totalCube;

                for (byte i = 0; i < quoteData.m_lPiece.Length; i++)
                {
                    sbiItems.Append("<RateItemViewModel>");

                    //totalCube = 0.0;
                    length = Convert.ToInt16(quoteData.m_lPiece[i].Length);
                    width  = Convert.ToInt16(quoteData.m_lPiece[i].Width);
                    height = Convert.ToInt16(quoteData.m_lPiece[i].Height);

                    if (length > 0)
                    {
                        totalCube = (length * width * height) / 1728;
                    }
                    else
                    {
                        totalCube = 0;
                    }

                    sbiItems.Append(string.Concat("<Cube>", totalCube, "</Cube>"));

                    sbiItems.Append(string.Concat("<DimensionUnits>in</DimensionUnits>"));

                    if (quoteData.m_lPiece[i].FreightClass.Contains("."))
                    {
                        fClass = quoteData.m_lPiece[i].FreightClass;
                    }
                    else
                    {
                        fClass = string.Concat(quoteData.m_lPiece[i].FreightClass, ".0");
                    }

                    sbiItems.Append(string.Concat("<FreightClass>", fClass, "</FreightClass>"));
                    sbiItems.Append(string.Concat("<Height>", (int)quoteData.m_lPiece[i].Height, ".0</Height>"));
                    sbiItems.Append(string.Concat("<Length>", (int)quoteData.m_lPiece[i].Length, ".0</Length>"));
                    sbiItems.Append(string.Concat("<Name>ItemName</Name>"));
                    sbiItems.Append(string.Concat("<Quantity>", quoteData.m_lPiece[i].Quantity, "</Quantity>"));
                    sbiItems.Append(string.Concat("<QuantityUnits>Unit</QuantityUnits>"));

                    if (is_Estes_HHG_Under_500 == true || is_Estes_HHG_Under_500_GLTL == true)
                    {
                        double actual_weight = quoteData.m_lPiece[i].Weight - quoteData.extraWeight;
                        sbiItems.Append(string.Concat("<Weight>", (int)actual_weight, ".0</Weight>"));
                    }
                    else
                    {
                        sbiItems.Append(string.Concat("<Weight>", (int)quoteData.m_lPiece[i].Weight, ".0</Weight>"));//800.0
                    }
                    sbiItems.Append(string.Concat("<WeightUnits>lb</WeightUnits>"));
                    sbiItems.Append(string.Concat("<Width>", (int)quoteData.m_lPiece[i].Width, ".0</Width>"));

                    sbiItems.Append("</RateItemViewModel>");
                }

                #endregion

                #region Country

                string originCountry = "USA", destinationCountry = "USA";

                if (!quoteData.origCountry.Contains("US"))
                {
                    originCountry = quoteData.origCountry;
                }

                if (!quoteData.destCountry.Contains("US"))
                {
                    destinationCountry = quoteData.destCountry;
                }

                #endregion

                #region Request Data XML string

                data = string.Concat("<RateRequestViewModel xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://schemas.datacontract.org/2004/07/Rrdl.Dls.Proxy\">",
                                     //"<Constraints>",
                                     //"<ServiceFlags>",
                                     //"<ServiceFlagViewModel>",
                                     //"<ServiceCode>RES1</ServiceCode>",
                                     //"</ServiceFlagViewModel>",
                                     //"</ServiceFlags>",
                                     //"</Constraints>",
                                     accessorials,
                                     "<DropEvent>",
                                     "<City>", quoteData.destCity, "</City>",
                                     "<Country>", destinationCountry, "</Country>",
                                     "<Date>", year, "-", month, "-", day, "T22:00:00.000000</Date>",
                                     "<State>", quoteData.destState, "</State>",
                                     "<Zip>", quoteData.destZip, "</Zip>",
                                     "</DropEvent>",
                                     "<IsCompanyAccountNumber>true</IsCompanyAccountNumber>",
                                     "<Items>",
                                     sbiItems,
                                     #region Not used
                                     //"<RateItemViewModel>",
                                     //    "<Cube>100</Cube>",
                                     //    "<DimensionUnits>in</DimensionUnits>",
                                     //    "<FreightClass>70.0</FreightClass>",
                                     //    "<Height>48.0</Height>",
                                     //    "<Length>42.0</Length>",
                                     //    "<Name>ItemName</Name>",
                                     //    "<Quantity>610</Quantity>",
                                     //    "<QuantityUnits>Unit</QuantityUnits>",
                                     //    "<Weight>800.0</Weight>",
                                     //    "<WeightUnits>lb</WeightUnits>",
                                     //    "<Width>42.0</Width>",
                                     //"</RateItemViewModel>",
                                     #endregion
                                     "</Items>",
                                     "<LinearFeet>4</LinearFeet>",
                                     "<MaxPriceSheet>6</MaxPriceSheet>",
                                     "<PickupEvent>",
                                     "<City>", quoteData.origCity, "</City>",
                                     "<Country>", originCountry, "</Country>",
                                     "<Date>", year, "-", month, "-", day, "T10:00:00.000000</Date>",
                                     "<State>", quoteData.origState, "</State>",
                                     "<Zip>", quoteData.origZip, "</Zip>",
                                     "</PickupEvent>",
                                     "<ReturnAssociatedCarrierPricesheet>true</ReturnAssociatedCarrierPricesheet>",
                                     "<ShowInsurance>true</ShowInsurance>",
                                     "</RateRequestViewModel>");

                //if (guaranteedService == false)
                //{

                //}

                #endregion

                #endregion

                doc = getResponseFromDLS(data);

                string res_part_1 = "", res_part_2 = "";
                if (doc.Length > 1000)
                {
                    res_part_1 = doc.Remove(doc.Length / 2);
                    res_part_2 = doc.Substring(doc.Length / 2);
                }

                if (guaranteedService == false)
                {
                    if (is_Estes_HHG_Under_500 == true)
                    {
                    }
                    else if (UserName == "The Exchange")
                    {
                        //DB.Log("getRateFromDLS_cust_rates res_part_1", res_part_1);
                        //DB.Log("getRateFromDLS_cust_rates res_part_2", res_part_2);
                    }
                    else if (UserName == "Ben Franklin Crafts - Macon")
                    {
                        //DB.Log("getRateFromDLS Ben Franklin Crafts - Macon res_part_1", res_part_1);
                        //DB.Log("getRateFromDLS Ben Franklin Crafts - Macon res_part_2", res_part_2);
                    }
                    else if (UserName == "Genera Corp")
                    {
                        DB.Log("getRateFromDLS Genera Corp res_part_1", res_part_1);
                        DB.Log("getRateFromDLS Genera Corp res_part_2", res_part_2);
                    }
                    else
                    {
                        // PNW - Burien WA
                        //DB.Log("getRateFromDLS res_part_1", res_part_1);
                        //DB.Log("getRateFromDLS res_part_2", res_part_2);
                    }
                }

                //doc = (string)HelperFuncs.generic_http_request_addHeaders("string", container, url, referrer, contentType, accept, method,
                //    data, false, headerNames, headerValues);

                // Gather results into an object
                Parser parser = new Parser(ref quoteData, ref UserName, ref guaranteedService, ref is_Estes_HHG_Under_500);

                if (UserName == "The Exchange")
                {
                    // Do nothing
                    parser.Parse_results_cust_rates(ref dlsPricesheets, ref doc);
                }
                else
                {
                    parser.Parse_results(ref dlsPricesheets, ref doc, ref isOverlengthUPS);
                }

                dlsPricesheets = dlsPricesheets.Distinct().ToList();
            }
            catch (Exception e)
            {
                DB.Log("getRateFromDLS", e.ToString());
            }
        }