Igor 5 сар өмнө
parent
commit
cc70d64549

+ 25 - 0
DiagramPage.xaml

@@ -0,0 +1,25 @@
+<Page x:Class="WpfApp1.DiagramPage"
+      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:WpfApp1"
+      mc:Ignorable="d" 
+      d:DesignHeight="450" d:DesignWidth="800"
+      Title="DiagramPage">
+
+    <Grid>
+        <Grid.RowDefinitions>
+            <RowDefinition Height="75"/>
+            <RowDefinition Height="*"/>
+            <RowDefinition Height="75"/>
+        </Grid.RowDefinitions>
+        <Image Source="/Resources/logo.png" Margin="541,0,3,0"/>
+        <Grid Background="#FF90D5FF" Panel.ZIndex="-2"></Grid>
+        <Grid Grid.Row="2" Background="#FF90D5FF"></Grid>
+        <Frame NavigationUIVisibility="Hidden" ContentRendered="MainFrame_ContentRendered" Grid.Row="1" Name="MainFrame"></Frame>
+        <StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
+            <Button Content="Экспорт в Excel" Width="175" x:Name="BtnExportToExcel" Click="BtnExportToExcel_Click"/>
+        </StackPanel>
+    </Grid>
+</Page>

+ 116 - 0
DiagramPage.xaml.cs

@@ -0,0 +1,116 @@
+using Microsoft.Office.Interop.Excel;
+using System;
+using System.Collections.Generic;
+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;
+using WpfApp1.Entities;
+using Excel = Microsoft.Office.Interop.Excel;
+
+namespace WpfApp1
+{
+    /// <summary>
+    /// Логика взаимодействия для DiagramPage.xaml
+    /// </summary>
+    public partial class DiagramPage : Page
+    {
+        private user20Entities _context = new user20Entities();
+        //List<string> listStatus = new List<string>()
+        //{
+        //    "запланирована", "выполнена", "отмена", "исполняется"
+        //};
+        public DiagramPage()
+        {
+            InitializeComponent();
+            //ChartPayments.ChartAreas.Add(new ChartArea("Main"));
+
+            //var currentSeries = new Series("Количество")
+            //{
+            //    IsValueShowAsLabel = true
+            //};
+            //ChartPayments.Series.Add(currentSeries);
+            //ComboExecutor.ItemsSource = listStatus;
+            //ComboChartTypes.ItemsSource = Enum.GetValues(typeof(SeriesChartType));
+        }
+
+        private void BtnExportToExcel_Click(object sender, RoutedEventArgs e)
+        {
+            var allUsers = _context.User.ToList().OrderBy(p => p.FirstName).ToList();
+
+            var application = new Excel.Application();
+            application.SheetsInNewWorkbook = allUsers.Count();
+
+            Excel.Workbook workbook = application.Workbooks.Add(Type.Missing);
+
+            int startRowIndex = 1;
+            for (int i = 0; i < allUsers.Count(); i++)
+            {
+                Excel.Worksheet worksheet = application.Worksheets.Item[i + 1];
+                worksheet.Name = allUsers[i].FirstName;
+
+                worksheet.Cells[1][startRowIndex] = "Дата платежа";
+                worksheet.Cells[2][startRowIndex] = "Название";
+                worksheet.Cells[3][startRowIndex] = "Стоимость";
+                worksheet.Cells[4][startRowIndex] = "Колличество";
+                worksheet.Cells[5][startRowIndex] = "Сумма";
+
+                startRowIndex++;
+
+                var usersCategories = allUsers[i].Payments.OrderBy(p=>p.Date).GroupBy(p=>p.Category).OrderBy(p=>p.Key.Name);
+                foreach (var groupCategory in usersCategories)
+                {
+                    Excel.Range headRange = worksheet.Range[worksheet.Cells[1][startRowIndex], worksheet.Cells[5][startRowIndex]];
+                    headRange.Merge();
+                    headRange.Value = groupCategory.Key.Name;
+                    headRange.HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
+                    headRange.Font.Italic = true;
+
+                    startRowIndex++;
+
+                    foreach (var payment in groupCategory)
+                    {
+                        worksheet.Cells[1][startRowIndex] = payment.Date.ToString("dd.MM.yyyy HH:mm");
+                        worksheet.Cells[2][startRowIndex] = payment.Name;
+                        worksheet.Cells[3][startRowIndex] = payment.Price;
+                        worksheet.Cells[4][startRowIndex] = payment.Num;
+
+                        worksheet.Cells[5][startRowIndex].formula = $"+C{startRowIndex}*D{startRowIndex}";
+                        worksheet.Cells[3][startRowIndex].NumberFormat =
+                            worksheet.Cells[3][startRowIndex].NumberFormat = "#, ###.00";
+
+                        startRowIndex++;
+                    }
+                    Excel.Range sumRange = worksheet.Range[worksheet.Cells[1][startRowIndex], worksheet.Cells[4][startRowIndex]];
+                    sumRange.Merge();
+                    sumRange.Value = "Итого:";
+                    sumRange.HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter;
+
+                    worksheet.Cells[5][startRowIndex].Formula = $"=SUM(E{startRowIndex = groupCategory.Count()}:" +
+                        $"{startRowIndex - 1})";
+
+                    sumRange.Font.Bold = worksheet.Cells[5][startRowIndex].Font.Bold = true;
+                    worksheet.Cells[5][startRowIndex].NumberFormat = "#, ###.00";
+
+                    startRowIndex++;
+
+                    Excel.Range rangeBorders = worksheet.Range[worksheet.Cells[1][1], worksheet.Cells[5][startRowIndex - 1]];
+                    rangeBorders.Borders[Excel.XlBordersIndex.xlEdgeBottom].LineStyle =
+                    rangeBorders.Borders[Excel.XlBordersIndex.xlEdgeLeft].LineStyle =
+                    rangeBorders.Borders[Excel.XlBordersIndex.xlEdgeRight].LineStyle =
+                    rangeBorders.Borders[Excel.XlBordersIndex.xlEdgeTop].LineStyle =
+                    rangeBorders.Borders[Excel.XlBordersIndex.xlEdge].LineStyle =
+                    rangeBorders.Borders[Excel.XlBordersIndex.xlEdgeBottom].LineStyle =
+                }    
+            }
+        }
+    }
+}

+ 8 - 0
Entities/Task.cs

@@ -26,6 +26,14 @@ namespace WpfApp1.Entities
         public string WorkType { get; set; }
         public Nullable<System.DateTime> CompletedDateTime { get; set; }
         public bool IsDeleted { get; set; }
+
+        public string DeletedText
+        {
+            get
+            {
+                return (IsDeleted) ? "Удален" : "Не удален" ;
+            }
+        }
     
         public virtual Executor Executor { get; set; }
     }

+ 1 - 1
MainWindow.xaml.cs

@@ -26,7 +26,7 @@ namespace WpfApp1
         public MainWindow()
         {
             InitializeComponent();
-            MainFrame.Navigate(new AuthPage());
+            MainFrame.Navigate(new TaskPage());
             Manager.MainFrame = MainFrame;
 
             //ImportUsers();

+ 65 - 0
TaskPage.xaml

@@ -0,0 +1,65 @@
+<Page x:Class="WpfApp1.TaskPage"
+      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:WpfApp1"
+      mc:Ignorable="d" 
+      d:DesignHeight="450" d:DesignWidth="800"
+      Title="TaskPage">
+
+    <Grid>
+        <Grid.RowDefinitions>
+            <RowDefinition Height="auto"></RowDefinition>
+            <RowDefinition Height="*"></RowDefinition>
+        </Grid.RowDefinitions>
+
+            <WrapPanel Orientation="Horizontal" HorizontalAlignment="Center">
+                <StackPanel Orientation="Horizontal">
+                    <TextBlock Text="Введите название задания для поиска:" Width="220" TextAlignment="Right"></TextBlock>
+                    <TextBox Width="221" Name="TBoxSearch" TextChanged="TBoxSearch_TextChanged"></TextBox>
+                </StackPanel>
+                <StackPanel Orientation="Horizontal">
+                    <TextBlock Text="Выберите тип: " Width="95" TextAlignment="Right"></TextBlock>
+                <ComboBox Width="225" Name="ComboType" SelectionChanged="ComboType_SelectionChanged" DisplayMemberPath="WorkType"></ComboBox>
+                </StackPanel>
+                <CheckBox x:Name="CheckDeleted" Checked="CheckDeleted_Checked" Unchecked="CheckDeleted_Checked" Content="Показывать только не удаленные задания" HorizontalAlignment="Center"></CheckBox>
+            </WrapPanel>
+        
+        <ListView Grid.Row="1" Name="LViewTasks" ScrollViewer.HorizontalScrollBarVisibility="Disabled" HorizontalContentAlignment="Center">
+            <ListView.ItemsPanel>
+                <ItemsPanelTemplate>
+                    <WrapPanel Orientation="Horizontal" HorizontalAlignment="Center"></WrapPanel>
+                </ItemsPanelTemplate>
+            </ListView.ItemsPanel>
+            <ListView.ItemTemplate>
+                <DataTemplate>
+                    <Grid Margin="20" Width="400">
+                        <Grid.RowDefinitions>
+                            <RowDefinition Height="*"/>
+                            <RowDefinition Height="*"/>
+                            <RowDefinition Height="*"/>
+                            <RowDefinition Height="*"/>
+                        </Grid.RowDefinitions>
+                        <Border BorderBrush="Black" BorderThickness="1" Background="#FF90D5FF" ></Border>
+                        <StackPanel Height="300" Width="400">
+                            <StackPanel>
+                                <TextBlock Text="{Binding Title}" VerticalAlignment="Center" TextAlignment="Center" Width="390"  TextWrapping="Wrap" HorizontalAlignment="Center" 
+                                   Margin="5 5" FontSize="26" Grid.Row="0"></TextBlock>
+                                <Separator/>
+                                <StackPanel>
+                                    <TextBlock Text="{Binding CreateDateTime}" Margin = "5"></TextBlock>
+                                    <TextBlock Text="{Binding Deadline}" Margin = "5"></TextBlock>
+                                    <TextBlock Text="{Binding Time}" Margin = "5"></TextBlock>
+                                    <TextBlock Text="{Binding Status}" Margin = "5"></TextBlock>
+                                    <TextBlock Text="{Binding WorkType}" Margin = "5"></TextBlock>
+                                    <TextBlock Text="{Binding DeletedText}" Margin = "5"></TextBlock>
+                                </StackPanel>
+                            </StackPanel>
+                        </StackPanel>
+                    </Grid>
+                </DataTemplate>
+            </ListView.ItemTemplate>
+        </ListView>
+    </Grid>
+</Page>

+ 74 - 0
TaskPage.xaml.cs

@@ -0,0 +1,74 @@
+using System;
+using System.Collections.Generic;
+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;
+using WpfApp1.Entities;
+
+namespace WpfApp1
+{
+    /// <summary>
+    /// Логика взаимодействия для TaskPage.xaml
+    /// </summary>
+    public partial class TaskPage : Page
+    {
+        public TaskPage()
+        {
+            InitializeComponent();
+
+            LViewTasks.ItemsSource = user20Entities.GetContext().Task.ToList();
+
+            var allTypes = user20Entities.GetContext().Task.ToList();
+            allTypes.Insert(0, new WpfApp1.Entities.Task
+            {
+                Title = "Все типы"
+            });
+            ComboType.ItemsSource = allTypes;
+
+            CheckDeleted.IsChecked = true;
+            ComboType.SelectedIndex = 0;
+        }
+
+
+        private void TBoxSearch_TextChanged(object sender, TextChangedEventArgs e)
+        {
+            UpdateTasks();
+        }
+
+        private void UpdateTasks()
+        {
+            var searchText = TBoxSearch.Text.ToLower();
+            var Tasks = user20Entities.GetContext().Task.ToList();
+
+            var currentTasks = user20Entities.GetContext().Task.ToList();
+
+            if (ComboType.SelectedIndex > 0)
+                currentTasks = currentTasks.Where(p => p.WorkType == ComboType.SelectedItem).ToList();
+
+            currentTasks = currentTasks.Where(p => p.Title.ToLower().Contains(TBoxSearch.Text.ToLower())).ToList();
+            if (CheckDeleted.IsChecked.Value)
+                currentTasks = currentTasks.Where(p => p.IsDeleted).ToList();
+
+
+        }
+
+        private void CheckDeleted_Checked(object sender, RoutedEventArgs e)
+        {
+            UpdateTasks();
+        }
+
+        private void ComboType_SelectionChanged(object sender, SelectionChangedEventArgs e)
+        {
+            UpdateTasks();
+        }
+    }
+}

+ 43 - 0
WpfApp1.csproj

@@ -65,6 +65,12 @@
       <Generator>MSBuild:Compile</Generator>
       <SubType>Designer</SubType>
     </ApplicationDefinition>
+    <Compile Include="DiagramPage.xaml.cs">
+      <DependentUpon>DiagramPage.xaml</DependentUpon>
+    </Compile>
+    <Compile Include="TaskPage.xaml.cs">
+      <DependentUpon>TaskPage.xaml</DependentUpon>
+    </Compile>
     <Page Include="AddEditPage.xaml">
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>
@@ -73,6 +79,10 @@
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>
     </Page>
+    <Page Include="DiagramPage.xaml">
+      <SubType>Designer</SubType>
+      <Generator>MSBuild:Compile</Generator>
+    </Page>
     <Page Include="ListHotels.xaml">
       <SubType>Designer</SubType>
       <Generator>MSBuild:Compile</Generator>
@@ -125,6 +135,10 @@
       <DependentUpon>MainWindow.xaml</DependentUpon>
       <SubType>Code</SubType>
     </Compile>
+    <Page Include="TaskPage.xaml">
+      <SubType>Designer</SubType>
+      <Generator>MSBuild:Compile</Generator>
+    </Page>
   </ItemGroup>
   <ItemGroup>
     <Compile Include="Manager.cs" />
@@ -179,5 +193,34 @@
       <LastGenOutput>Model1.cs</LastGenOutput>
     </Content>
   </ItemGroup>
+  <ItemGroup>
+    <COMReference Include="Microsoft.Office.Core">
+      <Guid>{2DF8D04C-5BFA-101B-BDE5-00AA0044DE52}</Guid>
+      <VersionMajor>2</VersionMajor>
+      <VersionMinor>8</VersionMinor>
+      <Lcid>0</Lcid>
+      <WrapperTool>primary</WrapperTool>
+      <Isolated>False</Isolated>
+      <EmbedInteropTypes>True</EmbedInteropTypes>
+    </COMReference>
+    <COMReference Include="Microsoft.Office.Interop.Excel">
+      <Guid>{00020813-0000-0000-C000-000000000046}</Guid>
+      <VersionMajor>1</VersionMajor>
+      <VersionMinor>9</VersionMinor>
+      <Lcid>0</Lcid>
+      <WrapperTool>primary</WrapperTool>
+      <Isolated>False</Isolated>
+      <EmbedInteropTypes>True</EmbedInteropTypes>
+    </COMReference>
+    <COMReference Include="VBIDE">
+      <Guid>{0002E157-0000-0000-C000-000000000046}</Guid>
+      <VersionMajor>5</VersionMajor>
+      <VersionMinor>3</VersionMinor>
+      <Lcid>0</Lcid>
+      <WrapperTool>primary</WrapperTool>
+      <Isolated>False</Isolated>
+      <EmbedInteropTypes>True</EmbedInteropTypes>
+    </COMReference>
+  </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
 </Project>