コード例 #1
0
        private void CalcLP(string[] Fields, ITrack track)
        {
            //declares and assigns
            var dtRaces           = new DataTable();
            var dtAWRaces         = new DataTable();
            var iIndex            = 0;
            var iSurfaceIndex     = 325;
            var iPaceRatingsIndex = 815;
            var iAWSurfaceIndex   = 1402;
            int iOutVal;

            LP = 0;

            dtRaces.Columns.Add(new DataColumn("PaceRating", System.Type.GetType("System.Decimal")));
            dtAWRaces.Columns.Add(new DataColumn("PaceRating", System.Type.GetType("System.Decimal")));

            //process
            while (iIndex < 10)
            {
                iOutVal = 0;

                //get all allweather races
                if (Fields[iAWSurfaceIndex + iIndex].ToLower() == "a" && dtAWRaces.Rows.Count < 3)
                {
                    dtAWRaces.Rows.Add(dtAWRaces.NewRow());
                    dtAWRaces.Rows[dtAWRaces.Rows.Count - 1][0] = int.TryParse(Fields[iPaceRatingsIndex + iIndex], out iOutVal) ? iOutVal : 0;
                }

                //get all races of this track type
                if ((((Fields[iSurfaceIndex + iIndex].ToLower().Equals(track.TrackTypeShort.ToLower())) ||
                      ((track.AllWeather) && (Fields[iSurfaceIndex + iIndex].ToLower().Equals("t")))) &&
                     (!Fields[iAWSurfaceIndex + iIndex].ToLower().Equals("a"))) &&
                    (dtRaces.Rows.Count < 3))
                {
                    dtRaces.Rows.Add(dtRaces.NewRow());
                    dtRaces.Rows[dtRaces.Rows.Count - 1][0] = int.TryParse(Fields[iPaceRatingsIndex + iIndex], out iOutVal) ? iOutVal : 0;
                }

                //increment
                ++iIndex;
            }

            //if track is All Weather, and there are no races in the table to choose from, then use a Turf / Inner Turf race.
            if (track.AllWeather)
            {
                dtRaces.DefaultView.Sort   = "PaceRating desc";
                dtAWRaces.DefaultView.Sort = "PaceRating desc";

                LP = (dtAWRaces.Rows.Count > 0) ? Convert.ToInt32(dtAWRaces.DefaultView.ToTable().Rows[0]["PaceRating"].ToString()) : LP;
                LP = (LP.Equals((Decimal)0.00)) && (dtRaces.Rows.Count > 0) ? Convert.ToInt32(dtRaces.DefaultView.ToTable().Rows[0]["PaceRating"].ToString()) : LP;
            }
            else
            {
                switch (track.TrackTypeShort.ToLower())
                {
                case "t":
                    dtRaces.DefaultView.Sort   = "PaceRating desc";
                    dtAWRaces.DefaultView.Sort = "PaceRating desc";

                    LP = (dtRaces.Rows.Count > 0) ? Convert.ToInt32(dtRaces.DefaultView.ToTable().Rows[0]["PaceRating"].ToString()) : LP;
                    LP = (LP.Equals((Decimal)0.00)) && (dtAWRaces.Rows.Count > 0) ? Convert.ToInt32(dtAWRaces.DefaultView.ToTable().Rows[0]["PaceRating"].ToString()) : LP;

                    //if track is Turf / Inner Turf, and there are no races in the table to choose from, then use an All Weather race.
                    break;

                default:     //All others
                    if (dtRaces.Rows.Count > 0)
                    {
                        dtRaces.DefaultView.Sort = "PaceRating desc";
                        LP = Convert.ToInt32(dtRaces.DefaultView.ToTable().Rows[0]["PaceRating"].ToString());
                    }
                    break;
                }
            }
        }