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; }
//Translate CB private void RefreshComboboxes() { int savedindex = 0, j = 0; string savedvalue = "", ntFormat = " -nt"; DataTable temptable = new DataTable(); //Truck tab temptable = comboBoxUserTruckCompanyTrucks.DataSource as DataTable; if (temptable != null) { savedindex = comboBoxUserTruckCompanyTrucks.SelectedIndex; if (savedindex != -1) { savedvalue = comboBoxUserTruckCompanyTrucks.SelectedValue.ToString(); } //comboBoxUserTruckCompanyTrucks.SelectedIndexChanged -= comboBoxCompanyTrucks_SelectedIndexChanged; foreach (DataRow temp in temptable.Rows) { string source = temp[0].ToString(); string value = GaragesList.Find(x => x.Vehicles.Contains(source)).GarageNameTranslated; if (value != null && value != "") { temp["GarageName"] = value; } else { temp["GarageName"] = "-unknown-"; } } if (savedindex != -1) { comboBoxUserTruckCompanyTrucks.SelectedValue = savedvalue; } //comboBoxUserTruckCompanyTrucks.SelectedIndexChanged += comboBoxCompanyTrucks_SelectedIndexChanged; } //Trailer tab temptable = comboBoxUserTrailerCompanyTrailers.DataSource as DataTable; if (temptable != null) { savedindex = comboBoxUserTrailerCompanyTrailers.SelectedIndex; if (savedindex != -1) { savedvalue = comboBoxUserTrailerCompanyTrailers.SelectedValue.ToString(); } //comboBoxUserTrailerCompanyTrailers.SelectedIndexChanged -= comboBoxCompanyTrailers_SelectedIndexChanged; foreach (DataRow temp in temptable.Rows) { string source = temp[0].ToString(); if (source == "null") { continue; } string value = GaragesList.Find(x => x.Trailers.Contains(source)).GarageNameTranslated; if (value != null && value != "") { temp["GarageName"] = value; } else { temp["GarageName"] = "-unknown-"; } } if (savedindex != -1) { comboBoxUserTrailerCompanyTrailers.SelectedValue = savedvalue; } //comboBoxUserTrailerCompanyTrailers.SelectedIndexChanged += comboBoxCompanyTrailers_SelectedIndexChanged; } //Countries ComboBoxes temptable = comboBoxFreightMarketCountries.DataSource as DataTable; if (temptable != null) { savedindex = comboBoxFreightMarketCountries.SelectedIndex; if (savedindex != -1) { savedvalue = comboBoxFreightMarketCountries.SelectedValue.ToString(); } comboBoxFreightMarketCountries.SelectedIndexChanged -= comboBoxCountries_SelectedIndexChanged; //i = 0; foreach (DataRow temp in temptable.Rows) { string source = temp[0].ToString(); CountriesLngDict.TryGetValue(source, out string value); if (value != null && value != "") { temp[1] = value; } else { string CapName = CultureInfo.InvariantCulture.TextInfo.ToTitleCase(source); temp[1] = CapName; } } DataTable sortedDT = temptable.DefaultView.Table.Copy(); DataView dv = sortedDT.DefaultView; dv.Sort = "CountryName ASC"; sortedDT = dv.ToTable(); sortedDT.DefaultView.Sort = ""; //Shift All DataRow sourceRow = sortedDT.Select("Country = '+all'")[0]; int rowi = sortedDT.Rows.IndexOf(sourceRow); DataRow row = sortedDT.NewRow(); row.ItemArray = sourceRow.ItemArray; sortedDT.Rows.RemoveAt(rowi); sortedDT.Rows.InsertAt(row, 0); //Shift Unsorted try { DataRow[] tmpRows = sortedDT.Select("Country = '+unsorted'"); if (tmpRows.Count() > 0) { sourceRow = tmpRows[0]; rowi = sortedDT.Rows.IndexOf(sourceRow); row = sortedDT.NewRow(); row.ItemArray = sourceRow.ItemArray; sortedDT.Rows.RemoveAt(rowi); sortedDT.Rows.InsertAt(row, 1); } } catch { } comboBoxFreightMarketCountries.DataSource = sortedDT; if (savedindex != -1) { comboBoxFreightMarketCountries.SelectedValue = savedvalue; } else { comboBoxFreightMarketCountries.SelectedValue = "+all"; } comboBoxFreightMarketCountries.SelectedIndexChanged += comboBoxCountries_SelectedIndexChanged; } //Companies temptable = comboBoxFreightMarketCompanies.DataSource as DataTable; if (temptable != null) { savedindex = comboBoxFreightMarketCompanies.SelectedIndex; if (savedindex != -1) { savedvalue = comboBoxFreightMarketCompanies.SelectedValue.ToString(); } comboBoxFreightMarketCompanies.SelectedIndexChanged -= comboBoxCompanies_SelectedIndexChanged; //i = 0; foreach (DataRow temp in temptable.Rows) { string source = temp[0].ToString(); CompaniesLngDict.TryGetValue(source, out string value); if (value != null && value != "") { temp[1] = value; } else { temp[1] = source + ntFormat; } } DataTable sortedDT = temptable.DefaultView.Table.Copy(); DataView dv = sortedDT.DefaultView; dv.Sort = "CompanyName ASC"; sortedDT = dv.ToTable(); sortedDT.DefaultView.Sort = ""; DataRow sourceRow = sortedDT.Select("Company = '+all'")[0]; int rowi = sortedDT.Rows.IndexOf(sourceRow); DataRow row = sortedDT.NewRow(); row.ItemArray = sourceRow.ItemArray; sortedDT.Rows.RemoveAt(rowi); sortedDT.Rows.InsertAt(row, 0); comboBoxFreightMarketCompanies.DataSource = sortedDT; if (savedindex != -1) { comboBoxFreightMarketCompanies.SelectedValue = savedvalue; } else { comboBoxFreightMarketCompanies.SelectedValue = "+all"; } comboBoxFreightMarketCompanies.SelectedIndexChanged += comboBoxCompanies_SelectedIndexChanged; } ////// //Cities ComboBoxes ComboBox[] CitiesCB = { comboBoxFreightMarketSourceCity, comboBoxFreightMarketDestinationCity, comboBoxUserCompanyHQcity, comboBoxCargoMarketSourceCity }; EventHandler[] CitiesCBeh = { comboBoxSourceCity_SelectedIndexChanged, comboBoxDestinationCity_SelectedIndexChanged, comboBoxUserCompanyHQcity_SelectedIndexChanged, comboBoxSourceCityCM_SelectedIndexChanged }; j = 0; foreach (ComboBox tempCB in CitiesCB) { temptable = tempCB.DataSource as DataTable; if (temptable != null) { savedindex = tempCB.SelectedIndex; if (savedindex != -1) { savedvalue = tempCB.SelectedValue.ToString(); } tempCB.SelectedIndexChanged -= CitiesCBeh[j]; //i = 0; foreach (DataRow temp in temptable.Rows) { string source = temp[0].ToString(); CitiesLngDict.TryGetValue(source, out string value); if (value != null && value != "") { temp[1] = value; } else { temp[1] = source + ntFormat; } } if (savedindex != -1) { tempCB.SelectedValue = savedvalue; } tempCB.SelectedIndexChanged += CitiesCBeh[j]; j++; } } ////// //Companies ComboBoxes ComboBox[] CompaniesCB = { comboBoxFreightMarketSourceCompany, comboBoxFreightMarketDestinationCompany, comboBoxSourceCargoMarketCompany }; EventHandler[] CompaniesCBeh = { comboBoxSourceCompany_SelectedIndexChanged, comboBoxDestinationCompany_SelectedIndexChanged, comboBoxSourceCompanyCM_SelectedIndexChanged }; j = 0; foreach (ComboBox tempCB in CompaniesCB) { temptable = tempCB.DataSource as DataTable; if (temptable != null) { savedindex = tempCB.SelectedIndex; if (savedindex != -1) { savedvalue = tempCB.SelectedValue.ToString(); } tempCB.SelectedIndexChanged -= CompaniesCBeh[j]; //i = 0; foreach (DataRow temp in temptable.Rows) { string source = temp[0].ToString(); CompaniesLngDict.TryGetValue(source, out string value); if (value != null && value != "") { temp[1] = value; } else { temp[1] = source + ntFormat; } } if (savedindex != -1) { tempCB.SelectedValue = savedvalue; } tempCB.SelectedIndexChanged += CompaniesCBeh[j]; j++; } } //Freight Market //Cargo temptable = comboBoxFreightMarketCargoList.DataSource as DataTable; if (temptable != null) { savedindex = comboBoxFreightMarketCargoList.SelectedIndex; if (savedindex != -1) { savedvalue = comboBoxFreightMarketCargoList.SelectedValue.ToString(); } comboBoxFreightMarketCargoList.SelectedIndexChanged -= comboBoxCargoList_SelectedIndexChanged; //i = 0; foreach (DataRow temp in temptable.Rows) { string source = temp[0].ToString(); CargoLngDict.TryGetValue(source, out string value); if (value != null && value != "") { temp[1] = value; } else { temp[1] = source + ntFormat; } } if (savedindex != -1) { comboBoxFreightMarketCargoList.SelectedValue = savedvalue; } comboBoxFreightMarketCargoList.SelectedIndexChanged += comboBoxCargoList_SelectedIndexChanged; } //Urgency temptable = comboBoxFreightMarketUrgency.DataSource as DataTable; if (temptable != null) { //i = 0; foreach (DataRow temp in temptable.Rows) { string source = temp[0].ToString(); UrgencyLngDict.TryGetValue(source, out string value); if (value != null && value != "") { temp[1] = value; } else { temp[1] = source + ntFormat; } } } ////// //ListBoxes FillVisitedCities(listBoxVisitedCities.TopIndex); FillGaragesList(listBoxGarages.TopIndex); listBoxFreightMarketAddedJobs.Refresh(); }
private void FillUserCompanyTrucksList() { DataTable combDT = new DataTable(); DataColumn dc = new DataColumn("UserTruckNameless", typeof(string)); combDT.Columns.Add(dc); //dc = new DataColumn("UserTruckName", typeof(string)); //combDT.Columns.Add(dc); // dc = new DataColumn("TruckType", typeof(string)); combDT.Columns.Add(dc); dc = new DataColumn("TruckName", 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(UserTruckNameless <> '', '[' + {0} +'] ' + IIF(GarageName <> '', {1} +' || ','') + {2} + IIF(DriverName <> 'null', ' || In use - ' + {3},'')," + "'-- NONE --')", "TruckType", "GarageName", "TruckName", "DriverName"); combDT.Columns.Add(dcDisplay); // foreach (KeyValuePair <string, UserCompanyTruckData> UserTruck in UserTruckDictionary) { string truckname = ""; try { string templine = UserTruck.Value.Parts.Find(x => x.PartType == "truckbrandname").PartData.Find(xline => xline.StartsWith(" data_path:")); truckname = templine.Split(new char[] { '"' })[1].Split(new char[] { '/' })[4]; } catch { } TruckBrandsLngDict.TryGetValue(truckname, out string trucknamevalue); // string tmpTruckType = "", tmpTruckName = "", tmpGarageName = "", tmpDriverName = ""; if (UserTruckDictionary[UserTruck.Key].Users) { tmpTruckType = "U"; tmpGarageName = GaragesList.Find(x => x.Vehicles.Contains(UserTruck.Key)).GarageNameTranslated; } else { tmpTruckType = "Q"; } // if (trucknamevalue != null && trucknamevalue != "") { tmpTruckName = trucknamevalue; } else { tmpTruckName = truckname; } Garages tmpGrg = GaragesList.Where(tX => tX.Vehicles.Contains(UserTruck.Key))?.SingleOrDefault() ?? null; if (tmpGrg != null) { tmpDriverName = tmpGrg.Drivers[tmpGrg.Vehicles.IndexOf(UserTruck.Key)]; } else { tmpDriverName = UserDriverDictionary.Where(tX => tX.Value.AssignedTruck == UserTruck.Key)?.SingleOrDefault().Key ?? "null"; } if (tmpDriverName != null && 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(UserTruck.Key, tmpTruckType, tmpTruckName, tmpGarageName, tmpDriverName); } bool noTrucks = false; if (combDT.Rows.Count == 0) { combDT.Rows.Add("null");//, "-- NONE --"); //none noTrucks = true; } comboBoxUserTruckCompanyTrucks.ValueMember = "UserTruckNameless"; comboBoxUserTruckCompanyTrucks.DisplayMember = "DisplayMember"; comboBoxUserTruckCompanyTrucks.DataSource = combDT; if (!noTrucks) { //combDT.DefaultView.Sort = "UserTruckName ASC"; comboBoxUserTruckCompanyTrucks.Enabled = true; comboBoxUserTruckCompanyTrucks.SelectedValue = PlayerDataData.UserCompanyAssignedTruck; } else { comboBoxUserTruckCompanyTrucks.Enabled = false; comboBoxUserTruckCompanyTrucks.SelectedValue = "null"; } }
private void FillUserCompanyTrucksList() { DataTable combDT = new DataTable(); DataColumn dc = new DataColumn("UserTruckNameless", typeof(string)); combDT.Columns.Add(dc); //dc = new DataColumn("UserTruckName", typeof(string)); //combDT.Columns.Add(dc); // dc = new DataColumn("TruckType", typeof(string)); combDT.Columns.Add(dc); dc = new DataColumn("TruckName", typeof(string)); combDT.Columns.Add(dc); dc = new DataColumn("GarageName", typeof(string)); combDT.Columns.Add(dc); DataColumn dcDisplay = new DataColumn("DisplayMember"); dcDisplay.Expression = string.Format("IIF(UserTruckNameless <> ''," + "'[' + {0} +'] ' + IIF(GarageName <> '', {1} +' || ','',) + {2}," + "'-- NONE --')", "TruckType", "GarageName", "TruckName"); combDT.Columns.Add(dcDisplay); // foreach (KeyValuePair <string, UserCompanyTruckData> UserTruck in UserTruckDictionary) { string truckname = ""; try { string templine = UserTruck.Value.Parts.Find(x => x.PartType == "truckbrandname").PartData.Find(xline => xline.StartsWith(" data_path:")); truckname = templine.Split(new char[] { '"' })[1].Split(new char[] { '/' })[4]; } catch { } TruckBrandsLngDict.TryGetValue(truckname, out string trucknamevalue); // string tmpTruckType = "", tmpTruckName = "", tmpGarageName = ""; if (UserTruckDictionary[UserTruck.Key].Users) { tmpTruckType = "U"; tmpGarageName = GaragesList.Find(x => x.Vehicles.Contains(UserTruck.Key)).GarageNameTranslated; } else { tmpTruckType = "Q"; } // if (trucknamevalue != null && trucknamevalue != "") { tmpTruckName = trucknamevalue; } else { tmpTruckName = truckname; } // combDT.Rows.Add(UserTruck.Key, tmpTruckType, tmpTruckName, tmpGarageName); } bool noTrucks = false; if (combDT.Rows.Count == 0) { combDT.Rows.Add("null");//, "-- NONE --"); //none noTrucks = true; } comboBoxUserTruckCompanyTrucks.ValueMember = "UserTruckNameless"; comboBoxUserTruckCompanyTrucks.DisplayMember = "DisplayMember"; comboBoxUserTruckCompanyTrucks.DataSource = combDT; if (!noTrucks) { //combDT.DefaultView.Sort = "UserTruckName ASC"; comboBoxUserTruckCompanyTrucks.Enabled = true; comboBoxUserTruckCompanyTrucks.SelectedValue = PlayerDataData.UserCompanyAssignedTruck; } else { comboBoxUserTruckCompanyTrucks.Enabled = false; comboBoxUserTruckCompanyTrucks.SelectedValue = "null"; } }