Exemple #1
0
    public static void getOTR_RateDLS()
    {
        string[] cityStateCountryOrig = new string[3];
        string[] cityStateCountryDest = new string[3];

        string oState, dState, oCity, dCity, oCountry, dCountry;

        try
        {
            SharedRail.cityStateCountryByZip(ref cityStateCountryOrig, originZipGlobal);
            SharedRail.cityStateCountryByZip(ref cityStateCountryDest, destZipGlobal);

            if (!string.IsNullOrEmpty(cityStateCountryOrig[0]))
            {
                oState   = cityStateCountryOrig[1];
                oCity    = cityStateCountryOrig[0];
                oCountry = cityStateCountryOrig[2];
            }
            else
            {
                return;
            }
            if (!string.IsNullOrEmpty(cityStateCountryDest[0]))
            {
                dState   = cityStateCountryDest[1];
                dCity    = cityStateCountryDest[0];
                dCountry = cityStateCountryDest[2];
            }
            else
            {
                return;
            }

            SharedRail.getOTR_RateDLS(ref originZipGlobal, ref destZipGlobal, ref puDateGlobal, ref oCity, ref oState, ref oCountry,
                                      ref dCity, ref dState, ref dCountry);
        }
        catch (Exception e)
        {
            HelperFuncs.writeToSiteErrors("MG OTR", e.ToString());
        }
    }
Exemple #2
0
    public List <string[]> GetIntermodalRate(string username, string password, DateTime pickupDate, string originZip, string destinationZip,
                                             string[] additionalServices, ref int QuoteID)
    {
        try
        {
            usernameGlobal = username;
            string user = GetGCMUserNameByAPILogins(username, password);
            int[]  info = GetMarkupPercent(user);
            int    IntermodalMarkupPercent = info[0];
            int    IntermodalMinimum       = info[1];

            destZipGlobal   = destinationZip;
            originZipGlobal = originZip;

            //cityByZip();
            string[] cityStateCountryOrig = new string[3];
            string[] cityStateCountryDest = new string[3];

            SharedRail.cityStateCountryByZip(ref cityStateCountryOrig, originZip);
            SharedRail.cityStateCountryByZip(ref cityStateCountryDest, destinationZip);

            //originState = dr[0].ToString();
            //originCity = dr[1].ToString();
            //originCountry = dr[2].ToString();

            //destState = dr[0].ToString();
            //destCity = dr[1].ToString();
            //destCountry = dr[2].ToString();

            originCity    = cityStateCountryOrig[0];
            destCity      = cityStateCountryDest[0];
            originState   = cityStateCountryOrig[1];
            destState     = cityStateCountryDest[1];
            originCountry = cityStateCountryOrig[2];
            destCountry   = cityStateCountryDest[2];


            #region puDate

            puDateGlobal = pickupDate;

            DateTime tomorrow = DateTime.Today.AddDays(1);

            int comparison;
            comparison = puDateGlobal.CompareTo(tomorrow);

            if (comparison == -1) // date is earlier than tomorrow, set the date to tomorrow
            {
                puDateGlobal = tomorrow;
            }
            if (puDateGlobal.DayOfWeek.ToString() == "Saturday")
            {
                puDateGlobal = puDateGlobal.AddDays(2);
            }
            else if (puDateGlobal.DayOfWeek.ToString() == "Sunday")
            {
                puDateGlobal = puDateGlobal.AddDays(1);
            }
            #endregion

            HelperFuncs.writeToSiteErrors("GetIntermodalRate Demo", string.Concat(originZip, " ", destinationZip, " ", originCity, " ", destCity));

            //int QuoteID = 0;
            // Insert into database
            SharedRail.saveResults(false, ref originCity, ref destCity, ref originState, ref destState, ref usernameGlobal, ref results, ref puDateGlobal,
                                   ref QuoteID);

            #region Threads

            List <Thread> threads = new List <Thread>();
            results.Clear();
            threads.Clear();

            SharedRail.streamlineResultArray  = new string[13];
            SharedRail.csxiResultArray        = new string[13];
            SharedRail.modalXResultArray      = new string[13];
            SharedRail.integraResultArray     = new string[13];
            SharedRail.integraResultArray40FT = new string[13];
            SharedRail.integraResultArray45FT = new string[13];
            SharedRail.mgOtrResultArray       = new string[13];

            //SharedRail.MG_OTR_Result mgOtrRes = new SharedRail.MG_OTR_Result();

            SharedRail.synchronet20FT_DryResultArray       = new string[13];
            SharedRail.synchronet40FT_High_CubeResultArray = new string[13];
            SharedRail.synchronet45FT_High_CubeResultArray = new string[13];



            // New objects
            //SharedRail.streamlineResults = new List<IntermodalResult>();

            // Initialize the notification field to avoid null reference exception when checking for function success
            SharedRail.streamlineResultArray[0] = "";
            SharedRail.csxiResultArray[0]       = "";
            SharedRail.modalXResultArray[0]     = "";
            SharedRail.integraResultArray[0]    = "";
            SharedRail.mgOtrResultArray[0]      = "";

            SharedRail.synchronet20FT_DryResultArray[0]       = "";
            SharedRail.synchronet40FT_High_CubeResultArray[0] = "";
            SharedRail.synchronet45FT_High_CubeResultArray[0] = "";

            for (int i = 0; i < 8; i++)
            {
                Thread thread;
                //thread = new Thread(new ThreadStart(GetStreamlineInfo));
                if (i == 0)
                {
                    thread = new Thread(new ThreadStart(getRate_Streamline));
                    //continue;
                }
                else if (i == 1)
                {
                    //thread = new Thread(new ThreadStart(GetIntegraInfo));
                    //thread = new Thread(() => GetIntegraInfo(SharedRail.FiftyThreeFt));
                    continue;
                }
                else if (i == 2)
                {
                    thread = new Thread(new ThreadStart(GetModalX_Info));
                }
                else if (i.Equals(3))
                {
                    //thread = new Thread(new ThreadStart(getSynchronetInfo20));
                    continue;
                }
                else if (i.Equals(4))
                {
                    //thread = new Thread(new ThreadStart(getSynchronetInfo40));
                    continue;
                }
                else if (i.Equals(5))
                {
                    //thread = new Thread(new ThreadStart(getSynchronetInfo45));
                    continue;
                }
                else if (i.Equals(6))
                {
                    //thread = new Thread(new ThreadStart(getOTR_RateDLS));
                    continue;
                }
                //else if (i == 2)
                //{
                //    thread = new Thread(new ThreadStart(GetIDIInfo));
                //}

                else
                {
                    //thread = new Thread(new ThreadStart(GetCSXIInfo));
                    continue;
                }
                thread.SetApartmentState(ApartmentState.STA);
                thread.Start();
                thread.Name = i.ToString();
                threads.Add(thread);
            }


            foreach (Thread t in threads)
            {
                if (!t.Join(TimeSpan.FromSeconds(25)))
                {
                    t.Abort();
                }
            }

            GetIntegraInfo(SharedRail.FourtyFtHighCube);

            #endregion

            #region Gather all results to one results object

            decimal integra40cost = 0M, synchro40cost = 0M, integra45cost = 0M, synchro45cost = 0M;

            #region Get Synchro costs

            if (SharedRail.synchronet40FT_High_CubeResultArray[0] != null && SharedRail.synchronet40FT_High_CubeResultArray[0].Equals(SharedRail.success))
            {
                decimal.TryParse(SharedRail.synchronet40FT_High_CubeResultArray[2].Replace("$", "").Trim(), out synchro40cost);
                HelperFuncs.writeToSiteErrors("WS synchronet40FT_High_CubeResultArray", SharedRail.synchronet40FT_High_CubeResultArray[2]);
            }
            else
            {
                HelperFuncs.writeToSiteErrors("WS synchronet40FT_High_CubeResultArray", "null");
            }

            if (SharedRail.synchronet45FT_High_CubeResultArray[0] != null && SharedRail.synchronet45FT_High_CubeResultArray[0].Equals(SharedRail.success))
            {
                decimal.TryParse(SharedRail.synchronet45FT_High_CubeResultArray[2].Replace("$", "").Trim(), out synchro45cost);
                HelperFuncs.writeToSiteErrors("WS synchronet45FT_High_CubeResultArray", SharedRail.synchronet45FT_High_CubeResultArray[2]);
            }
            else
            {
                HelperFuncs.writeToSiteErrors("WS synchronet45FT_High_CubeResultArray", "null");
            }

            #endregion

            #region Get Integra costs

            if (SharedRail.integraResultArray40FT[0] != null && SharedRail.integraResultArray40FT[0].Equals(SharedRail.success))
            {
                if (SharedRail.integraResultArray40FT[0] != null && SharedRail.integraResultArray40FT[0].Equals(SharedRail.success))
                {
                    decimal.TryParse(SharedRail.integraResultArray40FT[2].Replace("$", "").Trim(), out integra40cost);
                    HelperFuncs.writeToSiteErrors("WS integraResultArray40FT", SharedRail.integraResultArray40FT[2]);
                }
                else
                {
                    HelperFuncs.writeToSiteErrors("WS integraResultArray40FT", "null");
                }

                if (SharedRail.integraResultArray45FT[0] != null && SharedRail.integraResultArray45FT[0].Equals(SharedRail.success))
                {
                    decimal.TryParse(SharedRail.integraResultArray45FT[2].Replace("$", "").Trim(), out integra45cost);
                    HelperFuncs.writeToSiteErrors("WS integraResultArray45FT", SharedRail.integraResultArray45FT[2]);
                }
                else
                {
                    HelperFuncs.writeToSiteErrors("WS integraResultArray45FT", "null");
                }
            }

            #endregion

            HelperFuncs.writeToSiteErrors("WS integra vs synchro", string.Concat(integra40cost, " ", integra45cost, " ", synchro40cost, " ", synchro45cost));

            // Gather all results to one results object
            if (SharedRail.streamlineResultArray[0].Equals(SharedRail.success))
            {
                results.Add(SharedRail.streamlineResultArray);

                //

                //IntermodalResult res = new IntermodalResult();
                //res.TotalCharge = streamRes.totalPrice;

                //if (transitDays.Equals(-1))
                //{
                //    res.EstimatedTransitTime = "10";
                //    res.EstimatedDeliveryDate = DateTime.Today.AddDays(10).ToShortDateString();
                //}
                //else
                //{
                //    res.EstimatedTransitTime = transitDays.ToString();
                //    res.EstimatedDeliveryDate = DateTime.Today.AddDays(transitDays).ToShortDateString();
                //}
                //res.Carrier = Streamline;
            }
            if (SharedRail.csxiResultArray[0].Equals(SharedRail.success))
            {
                results.Add(SharedRail.csxiResultArray);
            }
            if (SharedRail.modalXResultArray[0].Equals(SharedRail.success))
            {
                results.Add(SharedRail.modalXResultArray);
            }
            if (SharedRail.integraResultArray != null && SharedRail.integraResultArray[0] != null && SharedRail.integraResultArray[0].Equals(SharedRail.success))
            {
                results.Add(SharedRail.integraResultArray);
            }

            if (integra40cost > 0 && (integra40cost < synchro40cost || synchro40cost.Equals(0M)))
            {
                if (SharedRail.integraResultArray40FT != null && SharedRail.integraResultArray40FT[0] != null && SharedRail.integraResultArray40FT[0].Equals(SharedRail.success))
                {
                    results.Add(SharedRail.integraResultArray40FT);
                }
            }
            else if (synchro40cost > 0 && (synchro40cost < integra40cost || integra40cost.Equals(0M)))
            {
                if (SharedRail.synchronet40FT_High_CubeResultArray != null && !string.IsNullOrEmpty(SharedRail.synchronet40FT_High_CubeResultArray[0]) &&
                    SharedRail.synchronet40FT_High_CubeResultArray[0].Equals(SharedRail.success))
                {
                    results.Add(SharedRail.synchronet40FT_High_CubeResultArray);
                }
            }

            if (integra45cost > 0 && (integra45cost < synchro45cost || synchro45cost.Equals(0M)))
            {
                if (SharedRail.integraResultArray45FT != null && SharedRail.integraResultArray45FT[0] != null && SharedRail.integraResultArray45FT[0].Equals(SharedRail.success))
                {
                    results.Add(SharedRail.integraResultArray45FT);
                }
            }
            else if (synchro45cost > 0 && (synchro45cost < integra45cost || integra45cost.Equals(0M)))
            {
                if (SharedRail.synchronet45FT_High_CubeResultArray != null && !string.IsNullOrEmpty(SharedRail.synchronet45FT_High_CubeResultArray[0]) &&
                    SharedRail.synchronet45FT_High_CubeResultArray[0].Equals(SharedRail.success))
                {
                    results.Add(SharedRail.synchronet45FT_High_CubeResultArray);
                }
            }

            //if (SharedRail.synchronet20FT_DryResultArray != null && !string.IsNullOrEmpty(SharedRail.synchronet20FT_DryResultArray[0]) &&
            //    SharedRail.synchronet20FT_DryResultArray[0].Equals(SharedRail.success))
            //{
            //    results.Add(SharedRail.synchronet20FT_DryResultArray);
            //}

            //if (SharedRail.synchronet40FT_High_CubeResultArray != null && !string.IsNullOrEmpty(SharedRail.synchronet40FT_High_CubeResultArray[0]) &&
            //    SharedRail.synchronet40FT_High_CubeResultArray[0].Equals(SharedRail.success))
            //{
            //    results.Add(SharedRail.synchronet40FT_High_CubeResultArray);
            //}

            //if (SharedRail.synchronet45FT_High_CubeResultArray != null && !string.IsNullOrEmpty(SharedRail.synchronet45FT_High_CubeResultArray[0]) &&
            //    SharedRail.synchronet45FT_High_CubeResultArray[0].Equals(SharedRail.success))
            //{
            //    results.Add(SharedRail.synchronet45FT_High_CubeResultArray);
            //}

            if (SharedRail.mgOtrResultArray != null && !string.IsNullOrEmpty(SharedRail.mgOtrResultArray[0]) &&
                SharedRail.mgOtrResultArray[0].Equals(SharedRail.success))
            {
                results.Add(SharedRail.mgOtrResultArray);
            }

            //for (byte i = 0; i < SharedRail.streamlineResults.Count; i++)
            //{
            //    resultsList.Add(SharedRail.streamlineResults[i]);
            //}

            #endregion

            SharedRail.saveResults(true, ref originCity, ref destCity, ref originState, ref destState, ref usernameGlobal, ref results, ref puDateGlobal,
                                   ref QuoteID);

            #region Add percentage

            Double rate, decPercent = (Double)IntermodalMarkupPercent / (Double)100, percentSum = 0;
            //Int32 transit;

            for (int i = 0; i < results.Count; i++)
            {
                //HelperFuncs.writeToSiteErrors("GetIntermodalRate user: "******"$", "").Replace(",", "") + " " +
                //    decPercent.ToString() + " " + IntermodalMinimum.ToString());
                if (!Double.TryParse(results[i][2].Replace("$", "").Replace(",", ""), out rate))
                {
                    continue;
                }
                percentSum = rate * decPercent;
                if (percentSum < IntermodalMinimum)
                {
                    rate         += IntermodalMinimum;
                    results[i][2] = "$" + rate;
                }
                else
                {
                    rate         += percentSum;
                    results[i][2] = "$" + rate;
                }
                //throw new Exception(IntermodalMarkupPercent + " " + decPercent + " " + percentSum + " " + IntermodalMinimum);
            }

            #endregion

            #region Valid through

            DateTime today = new DateTime();
            today = DateTime.Today;
            int weekendDays = 0, daysToAdd = 0;
            for (int i = 1; i < 6; i++)
            {
                if (today.AddDays(i).DayOfWeek.ToString() == "Saturday" || today.AddDays(i).DayOfWeek.ToString() == "Sunday")
                {
                    weekendDays++;
                }
            }
            if (weekendDays == 1)
            {
                if (today.DayOfWeek.ToString() == "Monday")
                {
                    daysToAdd = 2;
                }
                else if (today.DayOfWeek.ToString() == "Saturday")
                {
                    daysToAdd = 1;
                }
            }
            else if (weekendDays == 2)
            {
                daysToAdd = 2;
            }
            else //weekend days = 0
            {
                daysToAdd = 0;
            }

            validThrough = DateTime.Today.AddDays(5 + daysToAdd);
            string vThru = validThrough.ToShortDateString();

            #endregion

            #region Compare rates

            //int indOfMinRate = -1;
            //int indOfMinTransit = -1;
            if (results.Count == 0)   // No results
            {
                return(results);
            }

            for (int i = 0; i < results.Count; i++)
            {
                if (!Double.TryParse(results[i][2].Replace("$", "").Replace(",", ""), out rate))
                {
                    continue;
                }

                results[i][6]  = validThrough.ToShortDateString();
                results[i][7]  = originCity + ", " + originState;
                results[i][8]  = originCountry;
                results[i][9]  = destCity + ", " + destState;
                results[i][10] = destCountry;

                sortedResults.Add(results[i]);

                #region Not used
                //if (i == 0)
                //{
                //    minRate = rate;
                //    indOfMinRate = i;
                //}
                //if (minRate > rate)
                //{
                //    minRate = rate;
                //    indOfMinRate = i;
                //}
                #endregion

                //IntermodalResult res = new IntermodalResult();
                //res.TotalCharge = streamRes.totalPrice;

                //if (transitDays.Equals(-1))
                //{
                //    res.EstimatedTransitTime = "10";
                //    res.EstimatedDeliveryDate = DateTime.Today.AddDays(10).ToShortDateString();
                //}
                //else
                //{
                //    res.EstimatedTransitTime = transitDays.ToString();
                //    res.EstimatedDeliveryDate = DateTime.Today.AddDays(transitDays).ToShortDateString();
                //}
                //res.Carrier = Streamline;
            }

            #region Not used
            //find index of lowest transit
            //minTransit = Int32.MaxValue;
            //for (int j = 0; j < results.Count; j++)
            //{

            //    if (!Int32.TryParse(results[j][3], out transit))
            //    {

            //        if (results[j][1].Contains("IDI<(") == false)
            //        {
            //            try
            //            {
            //                //writeBugReport("could not parse transit " + results[j][3]);
            //                HelperFuncs.writeToSiteErrors("GetIntermodalRate", "could not parse transit " + results[j][3]);
            //            }
            //            catch { }
            //        }
            //        continue;
            //    }

            //    if (minTransit > transit)
            //    {
            //        minTransit = transit;
            //        indOfMinTransit = j;
            //    }
            //}



            //if (indOfMinRate != -1)
            //{
            //    if (indOfMinTransit > -1)
            //    {
            //        results[indOfMinTransit][2] = SharedRail.normalizeTrailNumbs(results[indOfMinTransit][2]);
            //    }
            //    results[indOfMinRate][2] = SharedRail.normalizeTrailNumbs(results[indOfMinRate][2]);
            //}



            //if (indOfMinRate != -1)
            //{
            //    if (results[indOfMinRate][1].Contains("Integra")) // in case of Integra
            //    {
            //        results[indOfMinRate][6] = results[indOfMinRate][4]; //doing this way to keep the function similar to Web Page function
            //    }
            //    else
            //    {
            //        results[indOfMinRate][6] = vThru;
            //    }
            //    results[indOfMinRate][7] = originCity + ", " + originState;
            //    results[indOfMinRate][8] = originCountry;
            //    results[indOfMinRate][9] = destCity + ", " + destState;
            //    results[indOfMinRate][10] = destCountry;

            //    if (results[indOfMinRate][1].Contains("IDI<(")) // in case of IDI
            //    {
            //        results[indOfMinRate][3] = "";
            //        results[indOfMinRate][4] = "";
            //        results[indOfMinRate][5] = "";
            //        sortedResults.Add(results[indOfMinRate]);
            //    }
            //    else
            //    {
            //        sortedResults.Add(results[indOfMinRate]);
            //    }
            //}

            //if (indOfMinTransit != -1 && (indOfMinTransit != indOfMinRate) && (results[indOfMinTransit][3] != results[indOfMinRate][3])) // transit time shorter but rate higher
            //{
            //    if (results[indOfMinTransit][1].Contains("Integra")) // in case of Integra
            //    {
            //        results[indOfMinTransit][6] = results[indOfMinTransit][4]; //doing this way to keep the function similar to Web Page function
            //    }
            //    else
            //    {
            //        results[indOfMinTransit][6] = vThru;
            //    }
            //    results[indOfMinTransit][7] = originCity + ", " + originState;
            //    results[indOfMinTransit][8] = originCountry;
            //    results[indOfMinTransit][9] = destCity + ", " + destState;
            //    results[indOfMinTransit][10] = destCountry;

            //    sortedResults.Add(results[indOfMinTransit]);
            //}
            #endregion

            #endregion

            return(sortedResults);
        }
        catch (Exception exep)
        {
            HelperFuncs.writeToSiteErrors("GetIntermodalRate", exep.ToString());
            return(results);
        }
    }