コード例 #1
0
        private void FillUserCompanyTrailerList()
        {
            DataTable  combDT = new DataTable();
            DataColumn dc     = new DataColumn("UserTrailerkNameless", typeof(string));

            combDT.Columns.Add(dc);

            dc = new DataColumn("UserTrailerName", typeof(string));
            combDT.Columns.Add(dc);


            combDT.Rows.Add("null", "-- NONE --"); //none

            foreach (KeyValuePair <string, UserCompanyTruckData> UserTrailer in UserTrailerDictionary)
            {
                if (UserTrailer.Value.Main)
                {
                    string trailername = "";

                    if (UserTrailerDictionary[UserTrailer.Key].Users)
                    {
                        trailername = "[U] ";
                    }
                    else
                    {
                        trailername = "[Q] ";
                    }

                    trailername += UserTrailer.Key;

                    string trailerdef = UserTrailerDictionary[UserTrailer.Key].Parts.Find(x => x.PartType == "trailerdef").PartNameless;

                    /*
                     * try
                     * {
                     *  string source_name = UserTrailerDefDictionary[trailerdef].Find(x => x.StartsWith(" source_name:")).Split(':')[1];
                     *
                     *  if (!source_name.Contains("null"))
                     *  {
                     *      trailername += source_name.Split(new char[] { '"' })[1].Trim(new char[] { ' ' }) + " | ";
                     *  }
                     * }
                     * catch { }
                     */

                    trailername += " [ ";

                    if (UserTrailerDefDictionary.Count > 0)
                    {
                        if (UserTrailerDefDictionary.ContainsKey(trailerdef))
                        {
                            string[] trailerDefPropertys = { "body_type", "axles", "chain_type" };
                            string[] trailerDefExtra     = { "{0}", "{0} axles", "{0}" };

                            int           iCounter      = 0;
                            List <string> CurTrailerDef = UserTrailerDefDictionary[trailerdef];

                            bool wasfound = false;

                            foreach (string Property in trailerDefPropertys)
                            {
                                try
                                {
                                    string tmp = CurTrailerDef.Find(x => x.StartsWith(" " + Property + ":")).Split(':')[1].Trim(new char[] { ' ' });

                                    if (wasfound)
                                    {
                                        trailername += " ";
                                    }
                                    trailername += String.Format(trailerDefExtra[iCounter], tmp);

                                    wasfound = true;
                                }
                                catch { wasfound = false; }
                                iCounter++;
                            }
                        }
                        else
                        {
                            trailername += trailerdef;
                        }
                    }
                    else
                    {
                        trailername += trailerdef;
                    }

                    trailername += " ]";

                    combDT.Rows.Add(UserTrailer.Key, trailername);
                }
            }

            if (combDT.Rows.Count > 0)
            {
                //combDT.DefaultView.Sort = "UserTrailerName ASC";
                comboBoxUserTrailerCompanyTrailers.Enabled       = true;
                comboBoxUserTrailerCompanyTrailers.ValueMember   = "UserTrailerkNameless";
                comboBoxUserTrailerCompanyTrailers.DisplayMember = "UserTrailerName";
                comboBoxUserTrailerCompanyTrailers.DataSource    = combDT;
                comboBoxUserTrailerCompanyTrailers.SelectedValue = PlayerDataV.UserCompanyAssignedTrailer;
            }
            else
            {
                comboBoxUserTrailerCompanyTrailers.Enabled = false;
            }
        }
コード例 #2
0
        private void FillUserCompanyTrailerList()
        {
            DataTable  combDT = new DataTable();
            DataColumn dc     = new DataColumn("UserTrailerNameless", typeof(string));

            combDT.Columns.Add(dc);

            dc = new DataColumn("TrailerType", typeof(string));
            combDT.Columns.Add(dc);

            dc = new DataColumn("TrailerName", typeof(string));
            combDT.Columns.Add(dc);

            dc = new DataColumn("GarageName", typeof(string));
            combDT.Columns.Add(dc);

            dc = new DataColumn("DriverName", typeof(string));
            combDT.Columns.Add(dc);

            DataColumn dcDisplay = new DataColumn("DisplayMember");

            dcDisplay.Expression = string.Format("IIF(UserTrailerNameless <> 'null', '[' + {0} +'] ' + IIF(GarageName <> '', {1} +' || ','') + {2} + IIF(DriverName <> 'null', ' || In use - ' + {3},'')," +
                                                 "'-- NONE --')",
                                                 "TrailerType", "GarageName", "TrailerName", "DriverName");
            combDT.Columns.Add(dcDisplay);
            //

            combDT.Rows.Add("null");

            foreach (KeyValuePair <string, UserCompanyTruckData> UserTrailer in UserTrailerDictionary)
            {
                if (UserTrailer.Value.Main)
                {
                    string trailername = "";
                    //
                    string tmpTrailerType = "", tmpTrailerkName = "", tmpGarageName = "", tmpDriverName = "";

                    if (UserTrailerDictionary[UserTrailer.Key].Users)
                    {
                        tmpTrailerType = "U";

                        tmpGarageName = GaragesList.Find(x => x.Trailers.Contains(UserTrailer.Key)).GarageNameTranslated;
                    }
                    else
                    {
                        tmpTrailerType = "Q";
                    }
                    //
                    string trailerdef = UserTrailerDictionary[UserTrailer.Key].Parts.Find(x => x.PartType == "trailerdef").PartNameless;

                    if (UserTrailerDefDictionary.Count > 0)
                    {
                        if (UserTrailerDefDictionary.ContainsKey(trailerdef))
                        {
                            string[] trailerDefPropertys = { "body_type", "axles", "chain_type" };
                            string[] trailerDefExtra     = { "{0}", "{0} axles", "{0}" };

                            int           iCounter      = 0;
                            List <string> CurTrailerDef = UserTrailerDefDictionary[trailerdef];

                            bool wasfound = false;

                            foreach (string Property in trailerDefPropertys)
                            {
                                try
                                {
                                    string tmp = CurTrailerDef.Find(x => x.StartsWith(" " + Property + ":")).Split(':')[1].Trim(new char[] { ' ' }).Replace('_', ' ');

                                    if (wasfound)
                                    {
                                        trailername += " | ";
                                    }
                                    trailername += String.Format(trailerDefExtra[iCounter], System.Globalization.CultureInfo.CurrentCulture.TextInfo.ToTitleCase(tmp));

                                    wasfound = true;
                                }
                                catch { wasfound = false; }

                                iCounter++;
                            }

                            tmpTrailerkName = trailername;
                        }
                        else
                        {
                            tmpTrailerkName = trailerdef;
                        }
                    }
                    else
                    {
                        tmpTrailerkName = trailerdef;
                    }

                    tmpDriverName = UserDriverDictionary.Where(tX => tX.Value.AssignedTrailer == UserTrailer.Key)?.SingleOrDefault().Key ?? "null";

                    if (tmpDriverName != "null")
                    {
                        if (PlayerDataData.UserDriver == tmpDriverName)
                        {
                            tmpDriverName = "> " + Utilities.TextUtilities.FromHexToString(Globals.SelectedProfile);
                        }
                        else
                        {
                            DriverNames.TryGetValue(tmpDriverName, out string _resultvalue);

                            if (_resultvalue != null && _resultvalue != "")
                            {
                                tmpDriverName = _resultvalue.TrimStart(new char[] { '+' });
                            }
                        }
                    }

                    combDT.Rows.Add(UserTrailer.Key, tmpTrailerType, tmpTrailerkName, tmpGarageName, tmpDriverName); //(UserTrailer.Key, trailername);
                }
            }

            if (combDT.Rows.Count > 1)
            {
                comboBoxUserTrailerCompanyTrailers.Enabled = true;
            }
            else
            {
                comboBoxUserTrailerCompanyTrailers.Enabled = false;
            }

            comboBoxUserTrailerCompanyTrailers.ValueMember   = "UserTrailerNameless";
            comboBoxUserTrailerCompanyTrailers.DisplayMember = "DisplayMember";
            comboBoxUserTrailerCompanyTrailers.DataSource    = combDT;


            comboBoxUserTrailerCompanyTrailers.SelectedValue = PlayerDataData.UserCompanyAssignedTrailer;
        }