Coder Social home page Coder Social logo

exam_pre_codes's Introduction

Exam_pre_codes

https://github.com/AsmodeyLostHaven/Teoretica_wpf.git

Способ как не создавать ненужные лишние окна:

код Window XAMl

<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
               <Grid.RowDefinitions>

           <RowDefinition Height="40*"/>

           <RowDefinition Height="177*"/>


       </Grid.RowDefinitions>

       <Grid.ColumnDefinitions>

           <ColumnDefinition Width="3*"/>

           <ColumnDefinition Width="13*"/>


       </Grid.ColumnDefinitions>

       <StackPanel x:Name="Menu_SP" Grid.Row="1" Grid.Column="0">

           <Label Content="MENU" 
          Foreground="#004572" FontSize="16"
          HorizontalAlignment="Center" />

           <Separator Margin="15" Background="White"/>

           <Button x:Name="btn_show_students"
           Width="120" Height="25"
           Content="Show Students"
           Foreground="#004572" FontSize="15" Click="btn_show_students_Click"
           />
           <Separator Margin="15" Background="White"/>

           <Button x:Name="btn_show_grades"
           Width="120" Height="25"
           Content="Show Grades"
           Foreground="#004572" FontSize="15" Click="btn_show_grades_Click"
           />

           <Separator Margin="15" Background="White"/>

           <Button x:Name="btn_show_exams"
           Width="120" Height="25"
           Content="Show Exams"
           Foreground="#004572" FontSize="15" Click="btn_show_exams_Click"
           />


           <Separator Margin="45" Background="White"/>

           <Button x:Name="btn_exit"
           Width="120" Height="25"
           Content="EXIT"
           Foreground="#004572" FontSize="15" Click="btn_exit_Click"
           />

       </StackPanel>


       <StackPanel x:Name="SP_Students" Grid.RowSpan="2" Grid.Column="1" Visibility="Collapsed">

           <Label Content="STUDENTS"
          FontSize="20" Foreground="#004572"
          HorizontalAlignment="Center"
          />

           <DataGrid x:Name="DG_Students" Height="318"/>

       </StackPanel>
    </Grid>
</Window>

ОБЪЯСНЕНИЕ

<Separator> - некий пробел между элементами. Настройка через Margin = " ".
И да, не забывайте в нем подгонять Background под фон того, на чем оно. Грид или StackPanel. По дефолту Separator имеет Белый цвет.

Как можно было замететь, я использую несколько "StackPanel". Это не запрещено и как раз выход для НЕ создания множества окон.

Visibility="Collapsed" 

только Collapsed вместо Hidden. С помощью кнопки меняем свойство. Ниже код

       private void btn_show_students_Click(object sender, RoutedEventArgs e)
       {
           if (SP_Students.Visibility == Visibility.Collapsed & SP_Grades.Visibility != Visibility.Visible & SP_Exams.Visibility != Visibility.Visible)
           {

               SP_Students.Visibility = Visibility.Visible;

           }
           else
           {
               SP_Students.Visibility = Visibility.Collapsed;
           }
       }
  • как можно было замететь, то у меня несколько SP (StackPanel), и тут я проверяю НЕ видны ли они. Вот так легко меняется свойство.

Но если уж так сильно любите окна, то вот код перемещения. Уникален для всех ОКОН

MenuScreen dashboard = new MenuScreen(); - где MenuScreen название Окна.
dashboard.Show();
this.Close();

Мой код (ГПТ) Логирования

SqlConnection sqlCon = new SqlConnection(@"Data Source=ИМЯ_СЕРВЕРА;Initial Catalog=ИМЯ_БАЗЫ;Integrated Security=True;Trust Server Certificate=True");
    try
    {
        if (sqlCon.State == ConnectionState.Closed)
            sqlCon.Open();
        String query = "SELECT * FROM SysLogin (SysLogin --> таблица) WHERE Login=@Login AND Password=@Password";
        SqlCommand sqlCmd = new SqlCommand(query, sqlCon);
        sqlCmd.CommandType = CommandType.Text;
        sqlCmd.Parameters.AddWithValue("@Login", txt_login.Text);
        sqlCmd.Parameters.AddWithValue("@Password", txt_passwd.Password);
        int role = Convert.ToInt32(sqlCmd.ExecuteScalar());
        switch (role)
        {
            case 1:
                MenuScreen dashboard = new MenuScreen();

                dashboard.Show();
                this.Close();
                MessageBox.Show("Access login. Welcome to back, Admin");
                break;

            default:
                MessageBox.Show("Username or Password is incorrect");
                break;
        }
    }

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

exam_pre_codes's People

Contributors

taedor avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.