Beispiel #1
0
        private void GetResult(string name)
        {
            timer.Stop();
            start = false;
            MessageBox.Show("Победил " + name);
            int victorianman;

            if (text1.Text == name)
            {
                victorianman = IDFirstCompetitor;
            }
            else
            {
                victorianman = IDSecondCompetitor;
            }

            db.RunInsertUpdateDelete("Update Battle set Result = " + victorianman + " Where Id = " + IDBattle + "");
            // Если это был последний бой 1 раунда, тогда составить новые второго раунда, если возможно
            int Checker = db.RunSelect("Select Result From Battle Where Result is NULL").Rows.Count;

            if (Checker == 0)
            {
                StartNewRound();
            }
            else
            {
                NextBattle();
            }
        }
Beispiel #2
0
        private void butEdit_Click(object sender, RoutedEventArgs e)
        {
            if (dg.SelectedItems.Count > 0)
            {
                ChangeVisible();
                gb.Header = "Редактирование мата";

                string run = db.RunInsertUpdateDelete("SELECT  [Name] as 'Наименовние' from Mat ");
                tbName.Text = ((DataRowView)dg.Items[dg.SelectedIndex]).Row[1].ToString();
            }
            else
            {
                MessageBox.Show("Выберите строку, которую необходимо отредактировать!");
            }
        }
Beispiel #3
0
        private void InsertCompetitor()
        {
            string gender = "";

            if (tbFirstName.Text != "" && tbLastName.Text != "" && tbAge.Text != "" && tbPatronymic.Text != "" && tbStret.Text != "" && tbWeight.Text != "" && cbSportClub.SelectedIndex != -1 && cbCity.SelectedIndex != -1)
            {
                if (rbF.IsChecked == true)
                {
                    gender = "Ж";
                }
                else
                {
                    gender = "М";
                }
                string query = "Insert into People (FIO, DateOfBirth, Gender, Id_SportClub,Id_City, Street, Weight, Age) values('"
                               + tbLastName.Text + " " + tbFirstName.Text + " " + tbPatronymic.Text + "','"
                               + Convert.ToDateTime(dpBirth.Text).ToString("yyyy-MM-dd") + "','" + gender + "','" + Convert.ToInt32(cbSportClub.SelectedValue.ToString())
                               + "','" + Convert.ToInt32(cbCity.SelectedValue.ToString()) + "','" + tbStret.Text
                               + "','" + Convert.ToInt32(tbWeight.Text) + "','" + Convert.ToDouble(tbAge.Text) + "')";

                MessageBox.Show(sql.RunInsertUpdateDelete(query));
                VisibleFalse();
            }
            else
            {
                MessageBox.Show("Не все поля заполнены!", "Внимание");
            }
        }
Beispiel #4
0
        private void butDelete_Click(object sender, RoutedEventArgs e)
        {
            if (UsersDataGrid.SelectedItem != null && UsersDataGrid.SelectedIndex != -1)
            {
                //DialogResult dialogResult = MessageBox.Show("Вы уверены, что хотите удалить эту запись таблицы?", "Проверка", MessageBoxButtons.YesNo);
                //if (dialogResult == DialogResult.Yes)
                //{
                DataRowView row = (DataRowView)UsersDataGrid.SelectedItems[0];
                db.RunInsertUpdateDelete("DELETE  FROM [dbo].[User] WHERE [Id] =" + row["Id"]);
                LoadTable();
                //}
            }

            else
            {
                MessageBox.Show("Выберите запись для удаления");
            }
        }
Beispiel #5
0
        private void but3_Click(object sender, RoutedEventArgs e)
        {
            if (dataGridSportC.SelectedItem != null && dataGridSportC.SelectedIndex != -1)
            {
                if (MessageBox.Show("Вы действительно хотите удалить запись?", "Удаление записи", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
                {
                    DataRowView row   = (DataRowView)dataGridSportC.SelectedItems[0];
                    string      query = "DELETE FROM [dbo].[SportClub] WHERE [Id] =" + row["Id"];
                    MessageBox.Show(db.RunInsertUpdateDelete(query));

                    LoadTable();
                }
            }
            else
            {
                MessageBox.Show("Выберите запись!");
            }
        }
Beispiel #6
0
        private void but4_Click(object sender, RoutedEventArgs e)//Добавить ОК
        {
            if (tb1.Text == "" || tb2.Text == "")
            {
                MessageBox.Show("Не все поля заполнены!");
                return;
            }

            if (gb1.Header.ToString() == "Добавить город")
            {
                string query = "insert into [dbo].[City] ([Name], [PochtaIndex]) values  ('" + tb1.Text + "', '" + tb2.Text + "')";
                MessageBox.Show(db.RunInsertUpdateDelete(query));
            }
            if (gb1.Header.ToString() == "Редактировать город")
            {
                DataRowView row   = (DataRowView)dataGridGorod.SelectedItems[0];
                string      query = "update [dbo].[City] set [Name]= '" + tb1.Text + "', [PochtaIndex]= '" + tb2.Text + "' where Id = '" + row["Id"] + "'";
                MessageBox.Show(db.RunInsertUpdateDelete(query));
            }
            LoadTable();//вывод данных в таблицу
            VisibleFalse();
        }
Beispiel #7
0
        private void but4_Click(object sender, RoutedEventArgs e)//Добавить ОК
        {
            if (tbOT.Text == "" || tbDO.Text == "")
            {
                MessageBox.Show("Не все поля заполнены!");
                return;
            }

            if (groupBox.Header.ToString() == "Добавить весовой класс")
            {
                string query = "insert into [dbo].[WeightClass] ([WeightFrom], [WeightTo]) values  ('" + Convert.ToInt32(tbOT.Text) + "', '" + Convert.ToInt32(tbDO.Text) + "')";
                MessageBox.Show(db.RunInsertUpdateDelete(query));
            }
            if (groupBox.Header.ToString() == "Редактировать весовой класс")
            {
                DataRowView row   = (DataRowView)dataGrid.SelectedItems[0];
                string      query = "update [dbo].[WeightClass] set [WeightFrom]= '" + Convert.ToInt32(tbOT.Text) + "', [WeightTo]= '" + Convert.ToInt32(tbDO.Text) + "' where Id = '" + row["Id"] + "'";
                MessageBox.Show(db.RunInsertUpdateDelete(query));
            }
            LoadTable();//вывод данных в таблицу
            VisibleFalse();
        }
Beispiel #8
0
 private void butLogin_Click(object sender, RoutedEventArgs e)
 {
     if (tbFIO.Text != "" && tbLogin.Text != "" && tbPassword.Password.ToString() != "" && tbEmail.Text != "")
     {
         MessageBox.Show(
             db.RunInsertUpdateDelete(@"Insert into [User](FIO, Login, Password, Admin, Email) 
             values('" + tbFIO.Text + "','" + tbLogin.Text + "','" + tbPassword.Password.ToString() + "','" + ((chbAdmin.IsChecked == true) ? 1 : 0) + "','" + tbEmail.Text + "')")
             );
         App.Current.Windows.OfType <MainWindow>().First().Show();
         Close();
     }
     else
     {
         MessageBox.Show("Заполните все поля!");
     }
 }
Beispiel #9
0
        private void butAdd_Click(object sender, RoutedEventArgs e)
        {
            DataTable dt = db.RunSelect(@"Select * From AgeClass");

            AgeClass[] AllAgeClass = new AgeClass[dt.Rows.Count];
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                AgeClass newAgeClass = new AgeClass();
                newAgeClass.Num  = Convert.ToInt32(dt.Rows[i][0]);
                newAgeClass.From = Convert.ToInt32(dt.Rows[i][1]);
                newAgeClass.To   = Convert.ToInt32(dt.Rows[i][2]);
                AllAgeClass[i]   = newAgeClass;
            }


            dt = db.RunSelect(@"Select * From WeightClass");
            WeightClass[] AllWeightClass = new WeightClass[dt.Rows.Count];
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                WeightClass newWeightClass = new WeightClass();
                newWeightClass.Num  = Convert.ToInt32(dt.Rows[i][0]);
                newWeightClass.From = Convert.ToInt32(dt.Rows[i][1]);
                newWeightClass.To   = Convert.ToInt32(dt.Rows[i][2]);
                AllWeightClass[i]   = newWeightClass;
            }



            dt = db.RunSelect(@"Select People.Id , People.FIO,SportClub.Name, City.Name,
                                                Weight,Age,Street,Gender,DateOfBirth
                                                    From (People inner join SportClub on People.Id_SportClub = SportClub.Id)
                                                                 inner join City      on People.Id_City      = City.Id");
            Kid[] AllKids = new Kid[dt.Rows.Count];
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                Kid newkid = new Kid();
                newkid.Num         = Convert.ToInt32(dt.Rows[i][0]);
                newkid.FIO         = dt.Rows[i][1].ToString();
                newkid.Sportclub   = dt.Rows[i][2].ToString();
                newkid.City        = dt.Rows[i][3].ToString();
                newkid.Weight      = Convert.ToDouble(dt.Rows[i][4].ToString());
                newkid.Age         = Convert.ToInt32(dt.Rows[i][5]);
                newkid.Street      = dt.Rows[i][6].ToString();
                newkid.Gender      = dt.Rows[i][7].ToString();
                newkid.Dateofbirth = Convert.ToDateTime(dt.Rows[i][8].ToString()).Date;
                foreach (AgeClass ac in AllAgeClass)
                {
                    if (newkid.Age >= ac.From && newkid.Age <= ac.To)
                    {
                        newkid.AgeClass = ac;
                        break;
                    }
                }

                foreach (WeightClass wc in AllWeightClass)
                {
                    if (newkid.Weight >= wc.From && newkid.Weight <= wc.To)
                    {
                        newkid.WeightClass = wc;
                        break;
                    }
                }
                if (newkid.Weight >= 55)
                {
                    newkid.WeightClass = AllWeightClass[AllWeightClass.Length - 1];
                }

                if (newkid.Weight != 5)
                {
                    int IDOfGroup = Convert.ToInt32(db.RunSelect(@"Select BattleGroup.Id 
                                                From (BattleGroup inner join AgeClass on BattleGroup.Id_Age = AgeClass.Id)
                                                                  inner join WeightClass on BattleGroup.Id_Weight = WeightClass.Id
                                                                        WHERE AgeClass.Id = '" + newkid.AgeClass.Num + "' and WeightClass.Id = '" + newkid.WeightClass.Num + "'").Rows[0][0]);
                    db.RunInsertUpdateDelete("Insert into PeopleBattleGroup values('" + newkid.Num + "', '" + IDOfGroup + "','" + DateTime.Now.Date + "')");

                    newkid.IDOfBattleGroup = IDOfGroup;
                    newkid.IDBattleG       = Convert.ToInt32(db.RunSelect(@"select top 1 Id  FROM PeopleBattleGroup Order by Id Desc").Rows[0][0]);
                    AllKids[i]             = newkid;
                }
            }



            //  разбить на группы если в них больше чем 5  (запариться с базой) Метод по соритировке



            dt = db.RunSelect("Select Id, Id_Weight, Id_Age From BattleGroup");
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                MYSort(Convert.ToInt32(dt.Rows[i][0]), Convert.ToInt32(dt.Rows[i][1]), Convert.ToInt32(dt.Rows[i][2]));
            }



            DataTable Mats = db.RunSelect("SELECT * From Mat");
            DataTable AllBattleGroupsInUse = db.RunSelect("SELECT Distinct Battle_Id From PeopleBattleGroup");
            DataTable CompetitorsInGroup;
            int       matid = 0;

            for (int group = 0; group < AllBattleGroupsInUse.Rows.Count; group++)
            {
                CompetitorsInGroup = db.RunSelect("Select Id  From PeopleBattleGroup Where Battle_Id = " + AllBattleGroupsInUse.Rows[group][0] + "");
                for (int i = 0; i < CompetitorsInGroup.Rows.Count - 1; i++)
                {
                    for (int j = i + 1; j < CompetitorsInGroup.Rows.Count; j++)
                    {
                        db.RunInsertUpdateDelete(@"Insert into Battle values(NULL," + Convert.ToInt32(Mats.Rows[matid][0]) + ",1," + Convert.ToInt32(CompetitorsInGroup.Rows[i][0]) + ", " + Convert.ToInt32(CompetitorsInGroup.Rows[j][0]) + ",NULL,NULL,NULL)");
                        matid = (matid + 1) % Mats.Rows.Count;
                    }
                }
            }
            //    if (!AllKids[i].HaveBattlealready)
            //    {
            //        for (int j = i + 1; j < AllKids.Length; j++)
            //        {
            //            if (AllKids[i].IDOfBattleGroup == AllKids[j].IDOfBattleGroup)
            //            {
            //
            //                AllKids[i].HaveBattlealready = true;
            //                AllKids[j].HaveBattlealready = true;
            //                break;
            //            }
            //        }
            //    }
            //}
            // конец
        }