コード例 #1
0
        //выход
        private void Button_Click_Exit(object sender, RoutedEventArgs e)
        {
            SportsmanWindow sportsmanWindow = new SportsmanWindow();

            sportsmanWindow.Show();
            Close();
        }
コード例 #2
0
        private void Button_exit_Click(object sender, RoutedEventArgs e)
        {
            if (WorkClass.role == 1)
            {
                TrenerWindow trenerWindow = new TrenerWindow();
                trenerWindow.Show();
            }
            else if (WorkClass.role == 0)
            {
                SportsmanWindow sportsmanWindow = new SportsmanWindow();
                sportsmanWindow.Show();
            }
            else
            {
                throw new Exception("Не выбрана роль");
            }

            Close();
        }
コード例 #3
0
        private void Input_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                SqlConnection cn;
                if (WorkClass.role == 1)
                {
                    cn = Connections.TrenerConnection.GetConnection();
                }
                else if (WorkClass.role == 0)
                {
                    cn = Connections.SportsmanConnection.GetConnection();
                }
                else
                {
                    throw new Exception("Не выбрана роль");
                }

                if (string.IsNullOrEmpty(Login.Text))
                {
                    throw new Exception("Поля не заполнены");
                }

                string loginParam = Login.Text;

                using (cn)
                {
                    cn.Open();
                    SqlCommand cmd = new SqlCommand("checkRole", cn);
                    cmd.CommandType = System.Data.CommandType.StoredProcedure;

                    SqlParameter login = new SqlParameter
                    {
                        ParameterName = "@login",
                        Value         = loginParam
                    };

                    SqlParameter typerole = new SqlParameter
                    {
                        ParameterName = "@typerole",
                        Value         = WorkClass.role
                    };

                    SqlParameter iduser = new SqlParameter
                    {
                        ParameterName = "@iduser",
                        SqlDbType     = System.Data.SqlDbType.Int,
                        Direction     = System.Data.ParameterDirection.Output
                    };

                    cmd.Parameters.Add(login);
                    cmd.Parameters.Add(typerole);
                    cmd.Parameters.Add(iduser);

                    cmd.ExecuteNonQuery();



                    id = Convert.ToInt32(cmd.Parameters["@iduser"].Value);
                    if (id < 0)
                    {
                        throw new Exception("Пользователь не найден");
                    }
                    else
                    {
                        if (WorkClass.role == 1)
                        {
                            WorkClass.trener.trenerid = id;
                            TrenerWindow trenerWindow = new TrenerWindow();
                            trenerWindow.Show();
                            Close();
                        }
                        else if (WorkClass.role == 0)
                        {
                            WorkClass.sportsman.sportsmanid = id;
                            SportsmanWindow sportsmanWindow = new SportsmanWindow();
                            sportsmanWindow.Show();
                            Close();
                        }
                    }

                    cn.Close();
                }
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }