gr672_bda 4 years ago
parent
commit
00766e5f44

+ 25 - 0
ProjectAnalogParus/FullInformationStudentPage.xaml

@@ -0,0 +1,25 @@
+<Page x:Class="ProjectAnalogParus.FullInformationStudentPage"
+      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
+      xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
+      xmlns:local="clr-namespace:ProjectAnalogParus"
+      mc:Ignorable="d" 
+      d:DesignHeight="450" d:DesignWidth="800"
+      Title="FullInformationStudentPage">
+
+    <Grid>
+        <TextBox Name="txtLastName" HorizontalAlignment="Left" Height="23" Margin="200,53,0,0" TextWrapping="Wrap"  VerticalAlignment="Top" Width="120"/>
+        <TextBox Name="txtFirstName" HorizontalAlignment="Left" Height="23" Margin="200,95,0,0" TextWrapping="Wrap"  VerticalAlignment="Top" Width="120"/>
+        <TextBox Name="txtMiddleName" HorizontalAlignment="Left" Height="23" Margin="200,138,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>
+        <ComboBox Name="cmbSpecialty" HorizontalAlignment="Left" Height="23" Margin="200,179,0,0"  VerticalAlignment="Top" Width="120"/>
+        <TextBox Name="txtNumberGroup" HorizontalAlignment="Left" Height="23" Margin="200,221,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>
+        <TextBox Name="txtCourse" HorizontalAlignment="Left" Height="23" Margin="200,259,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>
+        <Button Name="SaveInfo" Content="Сохранить" HorizontalAlignment="Left" Margin="82,352,0,0" VerticalAlignment="Top" Width="75" Click="EditInformationStudent_Click"/>
+        <Button Name="AddInfo" Content="Добавить" HorizontalAlignment="Left" Margin="82,352,0,0" VerticalAlignment="Top" Width="75" Click="AddInformationStudent_Click"/>
+        <Button  Content="Выход" HorizontalAlignment="Left" Margin="200,352,0,0" VerticalAlignment="Top" Width="75" Click="Cancel_Click"/>
+        <Button Content="Добавить фотографию" HorizontalAlignment="Left" Margin="33,221,0,0" VerticalAlignment="Top" Width="140" Height="23" Click="PhotoInsert_Click"/>
+        <Image Name="PhotoOfClent" HorizontalAlignment="Left" Height="149" Margin="33,53,0,0" VerticalAlignment="Top" Width="140"/>
+
+    </Grid>
+</Page>

+ 141 - 0
ProjectAnalogParus/FullInformationStudentPage.xaml.cs

@@ -0,0 +1,141 @@
+
+using Cake.Core.IO;
+using Microsoft.Win32;
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Navigation;
+using System.Windows.Shapes;
+
+namespace ProjectAnalogParus
+{
+    /// <summary>
+    /// Логика взаимодействия для FullInformationStudentPage.xaml
+    /// </summary>
+    public partial class FullInformationStudentPage : Page
+    {
+        gr672_bdaEntities db = new gr672_bdaEntities();
+        public int? IdStudent { get; set; }
+        public FullInformationStudentPage(int? StudentId)
+        {
+            InitializeComponent();
+
+            cmbSpecialty.ItemsSource = db.Specialty.ToList();
+            cmbSpecialty.DisplayMemberPath = "NameSpecialty";
+            cmbSpecialty.SelectedValuePath = "IdSpecialty";
+
+            IdStudent = StudentId;
+            if (StudentId  != null)
+            {
+                this.Title = "Дополнительная информация";
+                Student st = db.Student.SingleOrDefault(item => item.IdStudent == StudentId);
+                txtLastName.Text = st.LastName;
+                txtFirstName.Text = st.FirstName;
+                txtMiddleName.Text = st.Middlename;
+                cmbSpecialty.Text = st.Group.Specialty.NameSpecialty;
+                txtNumberGroup.Text = Convert.ToString(st.Group.NumberGroup);
+                txtCourse.Text = Convert.ToString(st.Group.Course);
+                AddInfo.Visibility = Visibility.Collapsed;
+            }
+            else 
+            {
+                this.Title = "Добавление студента";
+                SaveInfo.Visibility = Visibility.Collapsed;
+            }
+        }
+
+        private void EditInformationStudent_Click(object sender, RoutedEventArgs e)
+        {
+            if (txtCourse.Text == string.Empty && txtFirstName.Text == string.Empty && txtLastName.Text == string.Empty && txtMiddleName.Text == string.Empty && txtNumberGroup.Text == string.Empty && cmbSpecialty.Text == string.Empty)
+            {
+                MessageBox.Show("Ключевые поля не заполнены");
+            }
+            else
+            {
+                Student stud = db.Student.SingleOrDefault(item => item.IdStudent == IdStudent);
+                stud.LastName = txtLastName.Text;
+                stud.FirstName = txtFirstName.Text;
+                stud.Middlename = txtMiddleName.Text;
+                stud.Group.NumberGroup = Convert.ToInt32(txtNumberGroup.Text);
+                stud.Group.Course = Convert.ToInt32(txtCourse.Text);
+                stud.Group.SpecialtyId = Convert.ToInt32((cmbSpecialty.SelectedItem as Specialty).IdSpecialty);
+                db.SaveChanges();
+                MessageBox.Show("Данные изменены и сохранены");
+                FramePage.MainFrame.Navigate(new ListStudentPage());
+            }
+        }
+
+        private void Cancel_Click(object sender, RoutedEventArgs e)
+        {
+            FramePage.MainFrame.Navigate(new ListStudentPage());
+        }
+
+        private void AddInformationStudent_Click(object sender, RoutedEventArgs e)
+        {
+            if(txtCourse != null && txtFirstName != null && txtLastName != null && txtMiddleName != null && txtNumberGroup != null && cmbSpecialty != null)
+            {
+                Group group = new Group()
+                {
+                    NumberGroup = Convert.ToInt32(txtNumberGroup.Text),
+                    Course = Convert.ToInt32(txtCourse.Text),
+                    SpecialtyId = Convert.ToInt32((cmbSpecialty.SelectedItem as Specialty).IdSpecialty)
+                };
+
+                Student stud = new Student()
+                {
+                    LastName = txtLastName.Text,
+                    FirstName = txtFirstName.Text,
+                    Middlename = txtMiddleName.Text,
+                    GroupId = group.IdGroup                   
+
+                };      
+            
+                db.Student.Add(stud);
+                db.Group.Add(group);
+                db.SaveChanges();
+                MessageBox.Show("Студент добавлен!");
+            }
+            else
+            {
+                MessageBox.Show("Не все поля заполнены!");
+            }
+           
+        }
+        class ConvertImageToByte
+        {
+            public static byte[] ImageToByte(string Path)
+            {
+                byte[] image;
+                image = File.ReadAllBytes(Path);
+                return image;
+            }
+        }
+
+
+            private void PhotoInsert_Click(object sender, RoutedEventArgs e)
+            {
+                OpenFileDialog ofdPicture = new OpenFileDialog();
+                ofdPicture.Filter =
+                    "Image files|*.bmp;*.jpg;*.gif;*.png;*.tif|All files|*.*";
+                ofdPicture.FilterIndex = 1;
+
+                if (ofdPicture.ShowDialog() == true)
+                  PhotoOfClent.Source =
+                        new BitmapImage(new Uri(ofdPicture.FileName));
+
+
+            }
+        
+
+    }
+}

+ 5 - 5
ProjectAnalogParus/ListStudentPage.xaml

@@ -9,19 +9,19 @@
       Title="ListStudentPage" Loaded="LoadedWindows">
       Title="ListStudentPage" Loaded="LoadedWindows">
 
 
     <Grid>
     <Grid>
-        <DataGrid Name="Studentgrid" HorizontalAlignment="Left" AutoGenerateColumns="False" Height="150" Margin="10,10,0,0" VerticalAlignment="Top" Width="780" >
+        <DataGrid CanUserAddRows="False" Name="Studentgrid" HorizontalAlignment="Left" AutoGenerateColumns="False" Height="150" Margin="10,10,0,0" VerticalAlignment="Top" Width="780" >
 
 
             <DataGrid.Columns>
             <DataGrid.Columns>
                 <DataGridTextColumn Binding="{Binding IdStudent}" Header="Id" Width="*"/>
                 <DataGridTextColumn Binding="{Binding IdStudent}" Header="Id" Width="*"/>
                 <DataGridTextColumn Binding="{Binding LastName}" Header="Фамилия" Width="3*"/>
                 <DataGridTextColumn Binding="{Binding LastName}" Header="Фамилия" Width="3*"/>
                 <DataGridTextColumn Binding="{Binding FirstName}" Header="Имя" Width="3*" />
                 <DataGridTextColumn Binding="{Binding FirstName}" Header="Имя" Width="3*" />
                 <DataGridTextColumn Binding="{Binding Middlename}" Header="Отчество" Width="3*" />
                 <DataGridTextColumn Binding="{Binding Middlename}" Header="Отчество" Width="3*" />
-                <DataGridTextColumn Binding="{Binding Group.NumberGroup}" Header="Группа" Width="2*" />
-                <DataGridTextColumn Binding="{Binding Group.Specialty.NameSpecialty}" Header="Специальность" Width="6*" />
-                <DataGridTextColumn Binding="{Binding Group.Course}" Header="Курс" Width="1*" />
+                <DataGridTextColumn Binding="{Binding Group.NumberGroup}" Header="Группа" Width="2*" />                
             </DataGrid.Columns>
             </DataGrid.Columns>
 
 
         </DataGrid>
         </DataGrid>
-        
+        <Button Content="Дополнительная информация" HorizontalAlignment="Left" Margin="10,199,0,0" VerticalAlignment="Top" Width="191" Click="FullInformation_Click" Height="27"/>
+        <Button Content="Добавить студента" HorizontalAlignment="Left" Margin="235,199,0,0" VerticalAlignment="Top" Width="124" Height="27" Click="insertStudent_Click"/>
+
     </Grid>
     </Grid>
 </Page>
 </Page>

+ 20 - 4
ProjectAnalogParus/ListStudentPage.xaml.cs

@@ -20,17 +20,33 @@ namespace ProjectAnalogParus
     /// </summary>
     /// </summary>
     public partial class ListStudentPage : Page
     public partial class ListStudentPage : Page
     {
     {
+        gr672_bdaEntities db = new gr672_bdaEntities();
         public ListStudentPage()
         public ListStudentPage()
         {
         {
             InitializeComponent();
             InitializeComponent();
-            gr672_bdaEntities db = new gr672_bdaEntities();
+            
         }
         }
         private void LoadedWindows(object sender, RoutedEventArgs e)
         private void LoadedWindows(object sender, RoutedEventArgs e)
+        {            
+            Studentgrid.ItemsSource = db.Student.ToList();  
+        }
+
+        private void FullInformation_Click(object sender, RoutedEventArgs e)
         {
         {
-            gr672_bdaEntities db = new gr672_bdaEntities();
-            Studentgrid.ItemsSource = db.Student.ToList();          
+            Student stud = (Student)Studentgrid.SelectedItem;
+            if (stud != null)
+            {
+                FramePage.MainFrame.Navigate(new FullInformationStudentPage(stud.IdStudent));
+            }
+            else 
+            {
+                MessageBox.Show("Не выбрана строка!");
+            }
+        }
 
 
+        private void insertStudent_Click(object sender, RoutedEventArgs e)
+        {
+            FramePage.MainFrame.Navigate(new FullInformationStudentPage(null));
         }
         }
-       
     }
     }
 }
 }

+ 10 - 0
ProjectAnalogParus/ProjectAnalogParus.csproj

@@ -50,6 +50,9 @@
     <WarningLevel>4</WarningLevel>
     <WarningLevel>4</WarningLevel>
   </PropertyGroup>
   </PropertyGroup>
   <ItemGroup>
   <ItemGroup>
+    <Reference Include="Cake.Core, Version=1.1.0.0, Culture=neutral, processorArchitecture=MSIL">
+      <HintPath>..\packages\Cake.Core.1.1.0\lib\net46\Cake.Core.dll</HintPath>
+    </Reference>
     <Reference Include="Castle.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
     <Reference Include="Castle.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
       <HintPath>..\packages\Castle.Core.4.4.0\lib\net45\Castle.Core.dll</HintPath>
       <HintPath>..\packages\Castle.Core.4.4.0\lib\net45\Castle.Core.dll</HintPath>
     </Reference>
     </Reference>
@@ -160,6 +163,9 @@
     <Compile Include="Experience.cs">
     <Compile Include="Experience.cs">
       <DependentUpon>Model.tt</DependentUpon>
       <DependentUpon>Model.tt</DependentUpon>
     </Compile>
     </Compile>
+    <Compile Include="FullInformationStudentPage.xaml.cs">
+      <DependentUpon>FullInformationStudentPage.xaml</DependentUpon>
+    </Compile>
     <Compile Include="Gender.cs">
     <Compile Include="Gender.cs">
       <DependentUpon>Model.tt</DependentUpon>
       <DependentUpon>Model.tt</DependentUpon>
     </Compile>
     </Compile>
@@ -288,6 +294,10 @@
       <SubType>Designer</SubType>
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>
       <Generator>MSBuild:Compile</Generator>
     </Page>
     </Page>
+    <Page Include="FullInformationStudentPage.xaml">
+      <SubType>Designer</SubType>
+      <Generator>MSBuild:Compile</Generator>
+    </Page>
     <Page Include="InfoUserPage.xaml">
     <Page Include="InfoUserPage.xaml">
       <SubType>Designer</SubType>
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>
       <Generator>MSBuild:Compile</Generator>

+ 1 - 0
ProjectAnalogParus/packages.config

@@ -1,5 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <?xml version="1.0" encoding="utf-8"?>
 <packages>
 <packages>
+  <package id="Cake.Core" version="1.1.0" targetFramework="net472" />
   <package id="Castle.Core" version="4.4.0" targetFramework="net472" />
   <package id="Castle.Core" version="4.4.0" targetFramework="net472" />
   <package id="DocumentFormat.OpenXml" version="2.12.3" targetFramework="net472" />
   <package id="DocumentFormat.OpenXml" version="2.12.3" targetFramework="net472" />
   <package id="EntityFramework" version="6.2.0" targetFramework="net472" />
   <package id="EntityFramework" version="6.2.0" targetFramework="net472" />