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; }
private void UpdateTrailerPanelProgressBar(byte _number) { UserTrailerDictionary.TryGetValue(comboBoxUserTrailerCompanyTrailers.SelectedValue.ToString(), out UserCompanyTruckData SelectedUserCompanyTrailer); if (SelectedUserCompanyTrailer == null) { return; } string pnlname = "progressbarTrailerPart" + _number.ToString(), labelPartName = "labelTrailerPartDataName" + _number.ToString(); //Progres bar Panel pbPanel = groupBoxUserTrailerTrailerDetails.Controls.Find(pnlname, true).FirstOrDefault() as Panel; //Part name Label pnLabel = groupBoxUserTrailerTrailerDetails.Controls.Find(labelPartName, true).FirstOrDefault() as Label; //Repair button Button repairButton = groupBoxUserTrailerTrailerDetails.Controls.Find("buttonTrailerElRepair" + _number, true).FirstOrDefault() as Button; if (pbPanel != null) { List <UserCompanyTruckDataPart> DataPart = null; try { switch (_number) { case 0: { DataPart = SelectedUserCompanyTrailer.Parts.FindAll(xp => xp.PartType == "trailerdata"); break; } case 1: DataPart = SelectedUserCompanyTrailer.Parts.FindAll(xp => xp.PartType == "body"); break; case 2: DataPart = SelectedUserCompanyTrailer.Parts.FindAll(xp => xp.PartType == "chassis"); break; case 3: DataPart = SelectedUserCompanyTrailer.Parts.FindAll(xp => xp.PartType == "tire"); break; } } catch { repairButton.Enabled = false; return; } decimal _wear = 0; byte partCount = 0; if (DataPart != null && DataPart.Count > 0) { if (pnLabel != null) { if (_number != 0) { pnLabel.Text = DataPart[0].PartData.Find(xl => xl.StartsWith(" data_path:")).Split(new char[] { '"' })[1].Split(new char[] { '/' }).Last().Split(new char[] { '.' })[0]; } else { var tmp = UserDriverDictionary.Select(tx => tx.Value) .Where(tX => tX.AssignedTrailer == comboBoxUserTrailerCompanyTrailers.SelectedValue.ToString()).ToList(); if (tmp != null && tmp.Count > 0) { string tmpCargo = tmp[0].DriverJob.Cargo; if (CargoLngDict.TryGetValue(tmpCargo, out string value)) { if (value != null && value != "") { pnLabel.Text = value; } else { string CapName = CultureInfo.InvariantCulture.TextInfo.ToTitleCase(value); pnLabel.Text = CapName; } } } else { repairButton.Enabled = false; pbPanel.BackgroundImage = null; pnLabel.Text = ""; return; } } } foreach (UserCompanyTruckDataPart tmpPartData in DataPart) { try { string tmpWear = tmpPartData.PartData.Find(xl => xl.StartsWith(" wear:") || xl.StartsWith(" cargo_damage:")).Split(new char[] { ' ' })[2]; decimal _tmpWear = 0; if (tmpWear != "0" && tmpWear != "1") { _tmpWear = Utilities.NumericUtilities.HexFloatToDecimalFloat(tmpWear); } else if (tmpWear == "1") { _tmpWear = 1; } _wear += _tmpWear; partCount++; } catch { } } } else { pnLabel.Text = "none"; repairButton.Enabled = false; return; } _wear = _wear / partCount; if (_wear == 0) { repairButton.Enabled = false; } else { repairButton.Enabled = true; } // SolidBrush ppen = new SolidBrush(GetProgressbarColor(_wear)); int x = 0, y = 0, pnlwidth = (int)(pbPanel.Width * (1 - _wear)); Bitmap progress = new Bitmap(pbPanel.Width, pbPanel.Height); Graphics g = Graphics.FromImage(progress); g.FillRectangle(ppen, x, y, pnlwidth, pbPanel.Height); int fontSize = 12; StringFormat sf = new StringFormat(); sf.LineAlignment = StringAlignment.Center; sf.Alignment = StringAlignment.Center; GraphicsPath p = new GraphicsPath(); p.AddString( ((int)((1 - _wear) * 100)).ToString() + " %", // text to draw FontFamily.GenericSansSerif, // or any other font family (int)FontStyle.Bold, // font style (bold, italic, etc.) g.DpiY * fontSize / 72, // em size new Rectangle(0, 0, pbPanel.Width, pbPanel.Height), // location where to draw text sf); // set options here (e.g. center alignment) g.SmoothingMode = SmoothingMode.AntiAlias; g.FillPath(Brushes.Black, p); g.DrawPath(Pens.Black, p); pbPanel.BackgroundImage = progress; } }
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"; } }