Ejemplo n.º 1
0
        public void ReadBD(string BdName)
        {
            // Обнуление существующей БД
            Variables.sportsmens.Clear();

            // чтение БД (массив строк, строка = спортсмен)
            string[] rowData = File.ReadAllText(Variables.path + BdName + ".bd").Trim().Split('\n');

            // в строке: 0-Country 1-Name 2-Surname 3-Age 4-Sport 5-Gold 6-Silver 7-Bronze
            foreach (string item in rowData)
            {
                string[] sportsmenRowInfo = item.Trim().Split('_');

                Sportsmen sportsmen = new Sportsmen();

                sportsmen.Country = sportsmenRowInfo[0];
                sportsmen.Name    = sportsmenRowInfo[1];
                sportsmen.Surname = sportsmenRowInfo[2];
                sportsmen.Age     = int.Parse(sportsmenRowInfo[3]);
                sportsmen.Sport   = sportsmenRowInfo[4];
                sportsmen.Gold    = int.Parse(sportsmenRowInfo[5]);
                sportsmen.Silver  = int.Parse(sportsmenRowInfo[6]);
                sportsmen.Bronze  = int.Parse(sportsmenRowInfo[7]);

                Variables.sportsmens.Add(sportsmen);
            }
        }
Ejemplo n.º 2
0
        public Sportsmen RandomData()
        {
            Random    random    = new Random();
            Sportsmen sportsmen = new Sportsmen();

            sportsmen.Country = countryArray[random.Next(0, countryArray.Length)];
            switch (sportsmen.Country)
            {
            case "Japan":
                sportsmen.Name    = JapanNameArray[random.Next(0, JapanNameArray.Length)];
                sportsmen.Surname = JapanSurnameArray[random.Next(0, JapanSurnameArray.Length)];
                break;

            case "Germany":
                sportsmen.Name    = GermanyNameArray[random.Next(0, GermanyNameArray.Length)];
                sportsmen.Surname = GermanySurnameArray[random.Next(0, GermanySurnameArray.Length)];
                break;

            case "Russia":
                sportsmen.Name    = RussianNameArray[random.Next(0, RussianNameArray.Length)];
                sportsmen.Surname = RussianSurnameArray[random.Next(0, RussianSurnameArray.Length)];
                break;

            case "French":
                sportsmen.Name    = FrenchNameArray[random.Next(0, FrenchNameArray.Length)];
                sportsmen.Surname = FrenchSurnameArray[random.Next(0, FrenchSurnameArray.Length)];
                break;

            case "Gr. Britain":
                sportsmen.Name    = EnNameArray[random.Next(0, EnNameArray.Length)];
                sportsmen.Surname = EnSurnameArray[random.Next(0, EnSurnameArray.Length)];
                break;

            case "USA":
                sportsmen.Name    = EnNameArray[random.Next(0, EnNameArray.Length)];
                sportsmen.Surname = EnSurnameArray[random.Next(0, EnSurnameArray.Length)];
                break;

            case "Canada":
                sportsmen.Name    = CanadaNameArray[random.Next(0, CanadaNameArray.Length)];
                sportsmen.Surname = CanadaSurnameArray[random.Next(0, CanadaSurnameArray.Length)];
                break;
            }

            sportsmen.Age    = random.Next(25, 51);
            sportsmen.Sport  = Sport[random.Next(0, Sport.Length)];
            sportsmen.Gold   = random.Next(0, 8);
            sportsmen.Silver = random.Next(0, 14);
            sportsmen.Bronze = random.Next(0, 21);

            return(sportsmen);
        }
Ejemplo n.º 3
0
        private void RandomBut_Click(object sender, EventArgs e)
        {
            Sportsmen data = generator.RandomData();

            Country.Text = data.Country;
            NameT.Text   = data.Name;
            Surname.Text = data.Surname;
            Age.Text     = data.Age.ToString();
            Sport.Text   = data.Sport;
            Gold.Text    = data.Gold.ToString();
            Silver.Text  = data.Silver.ToString();
            Bronze.Text  = data.Bronze.ToString();
        }
Ejemplo n.º 4
0
        // buttons
        private void NewBut_Click(object sender, EventArgs e)
        {
            NewBut.Enabled = false;

            Sportsmen sportsmen = new Sportsmen();

            sportsmen.Country = Country.Text == "" ? "Country" : Country.Text;
            sportsmen.Name    = NameT.Text == "" ? "Name" : NameT.Text;
            sportsmen.Surname = Surname.Text == "" ? "Surname" : Surname.Text;
            sportsmen.Age     = Age.Text == "" ? 0 : int.Parse(Age.Text);
            sportsmen.Sport   = Sport.Text == "" ? "Sport" : Sport.Text;
            sportsmen.Gold    = Gold.Text == "" ? 0 : int.Parse(Gold.Text);
            sportsmen.Silver  = Silver.Text == "" ? 0 : int.Parse(Silver.Text);
            sportsmen.Bronze  = Bronze.Text == "" ? 0 : int.Parse(Bronze.Text);

            Variables.sportsmens.Add(sportsmen);

            NewBut.Enabled = true;
        }
Ejemplo n.º 5
0
        private void SaveBut_Click(object sender, EventArgs e)
        {
            SaveBut.Enabled = false;

            Variables.tmpIndex = Variables.sportsmens.IndexOf(Variables.SelectedSportsmen);

            Sportsmen sportsmen = new Sportsmen();

            sportsmen.Country = Country.Text;
            sportsmen.Name    = NameT.Text;
            sportsmen.Surname = Surname.Text;
            sportsmen.Age     = int.Parse(Age.Text);
            sportsmen.Sport   = Sport.Text;

            sportsmen.Gold   = int.Parse(Gold.Text);
            sportsmen.Silver = int.Parse(Silver.Text);
            sportsmen.Bronze = int.Parse(Bronze.Text);

            Variables.sportsmens[Variables.tmpIndex] = sportsmen;
        }
Ejemplo n.º 6
0
        // creating elements
        public Panel CreateElements_General(Sportsmen sportsmen, Tab1 tab)
        {
            #region Creating elements
            // главная панель
            Panel MainPanel = new Panel();
            MainPanel.Size = new Size(280, 82);

            MainPanel.BackColor   = defaultColor;
            MainPanel.BorderStyle = BorderStyle.FixedSingle;
            MainPanel.BringToFront();


            // страна, фамилия + имя, возраст, вид спорта
            Label countrylab = NewLabel(sportsmen.Country, new Point(1, 1));
            Label namelab    = NewLabel(sportsmen.Name + " " + sportsmen.Surname, new Point(1, 20));
            Label agelab     = NewLabel("Age " + sportsmen.Age, new Point(1, 39));
            Label sportlab   = NewLabel(sportsmen.Sport, new Point(1, 58));


            // золото
            PictureBox goldimage = NewPictureBox(Resources.gold, new Point(140, 5));
            Label      goldlab   = NewLabel(sportsmen.Gold.ToString(), new Point(140, 40));

            goldlab.TextAlign = ContentAlignment.MiddleCenter;
            goldlab.Size      = new Size(30, 15);


            // серебро
            PictureBox silverimage = NewPictureBox(Resources.silver, new Point(180, 5));
            Label      silverlab   = NewLabel(sportsmen.Silver.ToString(), new Point(180, 40));

            silverlab.TextAlign = ContentAlignment.MiddleCenter;
            silverlab.Size      = new Size(30, 15);

            // бронза
            PictureBox bronzeimage = NewPictureBox(Resources.bronze, new Point(220, 5));
            Label      bronzelab   = NewLabel(sportsmen.Bronze.ToString(), new Point(220, 40));

            bronzelab.TextAlign = ContentAlignment.MiddleCenter;
            bronzelab.Size      = new Size(30, 15);


            // кнопка выбора
            PictureBox edit = new PictureBox();
            edit.Image = Resources.right_arrow;

            edit.SizeMode = PictureBoxSizeMode.Zoom;

            edit.Size     = new Size(30, 30);
            edit.Location = new Point(250, 25);

            edit.MouseEnter += new EventHandler(Edit_MouseEnter);
            edit.MouseLeave += new EventHandler(Edit_MouseLeave);
            edit.Click      += new EventHandler(Edit_Click);
            #endregion

            // функции кнопки редактирования
            void Edit_Click(object sender, EventArgs e)
            {
                if (CurrentChoose != null)
                {
                    CurrentChoose.BackColor = defaultColor;
                }

                CurrentChoose           = MainPanel;
                CurrentChoose.BackColor = activeColor;


                // сохранение данных о текущем элементе
                Variables.SelectedSportsmen = sportsmen;
                Variables.SelectedPanel     = MainPanel;

                tab.SelectElement();
            }

            void Edit_MouseEnter(object sender, EventArgs e)
            {
                edit.Image = Resources.right_arrow_active;
            }

            void Edit_MouseLeave(object sender, EventArgs e)
            {
                edit.Image = Resources.right_arrow;
            }

            MainPanel.Controls.Add(countrylab);
            MainPanel.Controls.Add(namelab);
            MainPanel.Controls.Add(agelab);
            MainPanel.Controls.Add(sportlab);

            MainPanel.Controls.Add(goldimage);
            MainPanel.Controls.Add(silverimage);
            MainPanel.Controls.Add(bronzeimage);

            MainPanel.Controls.Add(goldlab);
            MainPanel.Controls.Add(silverlab);
            MainPanel.Controls.Add(bronzelab);

            MainPanel.Controls.Add(edit);


            return(MainPanel);
        }