Example #1
0
        //Translate CB
        private void RefreshComboboxes()
        {
            int       savedindex = 0, j = 0;
            string    savedvalue = "", ntFormat = " -nt";
            DataTable temptable = new DataTable();

            //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
                {
                    sourceRow = sortedDT.Select("Country = '+unsorted'")[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 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;
            }
        }