123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231 |
- using chernovik_company2.Pages;
- using Microsoft.Office.Interop.Word;
- 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 Word = Microsoft.Office.Interop.Word;
- namespace chernovik_company2
- {
- /// <summary>
- /// Логика взаимодействия для ListPage.xaml
- /// </summary>
- public partial class ListPage : System.Windows.Controls.Page
- {
- List<Material>MaterialsStart= BaseClass.Base.Material.ToList();
- List<Material> MaterialsFilter = BaseClass.Base.Material.ToList(); //не используется
- List<Material> MaterialsSearch = BaseClass.Base.Material.ToList(); //не используется
- int sortType = -1;
-
-
- public ListPage()
- {
- InitializeComponent();
- LVMaterials.ItemsSource = MaterialsStart;
- Filter.Items.Add("Все типы");
- List<MaterialType> mt = BaseClass.Base.MaterialType.ToList();
- for (int i = 0; i < mt.Count; i++)
- {
- Filter.Items.Add(mt[i].Title);
- }
- Filter.SelectedIndex = 0;
- }
-
- private void TbSupplier_Loaded(object sender, RoutedEventArgs e)
- {
- TextBlock tb = (TextBlock)sender;
- int index = Convert.ToInt32(tb.Uid);
- List<MaterialSupplier> mtList = BaseClass.Base.MaterialSupplier.Where(x => x.MaterialID == index).ToList();
- string str = "";
- foreach (MaterialSupplier item in mtList)
- {
- str += item.Supplier.Title + ", ";
- }
- if (mtList.Count == 0)
- {
- tb.Text = "Поставщики отсуствуют.";
- }
- else
- {
- tb.Text = "Поставщики:" + str.Substring(0, str.Length - 2);
- }
- }
- public void GetData(string search = "", string filter = "")
- {
- var list = BaseClass.Base.Material.ToList();
- int countBefore = list.Count;
- if ( !string.IsNullOrWhiteSpace(search))
- {
- list = list.Where(m => m.Title.Contains(search) || m.Title.ToLower().Contains(search) || m.Description.Contains(search)).ToList();
- }
- if (filter != "Все типы")
- {
- list = list.Where(m => m.MaterialType.Title == filter).ToList();
- }
- if (sortType == 1)
- {
- switch (Sort.SelectedIndex)
- {
- case 0: list = list.OrderByDescending(m => m.Title).ToList(); break;
- case 1: list = list.OrderByDescending(m => m.CountInStock).ToList(); break;
- case 2: list = list.OrderByDescending(m => m.Cost).ToList(); break;
- }
- }
- if (sortType == 0)
- {
- switch (Sort.SelectedIndex)
- {
- case 0: list = list.OrderBy(m => m.Title).ToList(); break;
- case 1: list = list.OrderBy(m => m.CountInStock).ToList(); break;
- case 2: list = list.OrderBy(m => m.Cost).ToList(); break;
- }
- }
- LVMaterials.ItemsSource = list;
- TBCount.Text = $"Общее количество записей: {list.Count} из {countBefore}";
- }
- private void Filters() //не используется
- {
- int index = Filter.SelectedIndex;
- if (index != 0)
- {
- MaterialsFilter = MaterialsStart.Where(x => x.MaterialTypeID == index).ToList();
- }
- else
- {
- MaterialsFilter = MaterialsStart;
- }
- }
- private void Search_Loaded(object sender, RoutedEventArgs e)
- {
- if (Search.Text != "")
- {
- MaterialsSearch = MaterialsStart.Where(x=> x.Title.Contains(Search.Text)).ToList();
- }
- }
- private void Search_TextChanged(object sender, TextChangedEventArgs e)
- {
- if (Filter != null)
- {
- GetData(Search.Text, Filter.Text);
- }
- }
- private void Filter_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- GetData(Search.Text, (Filter.SelectedValue.ToString()));
- }
- private void BtnDesc_Click(object sender, RoutedEventArgs e)
- {
- sortType = 1;
- GetData(Search.Text, Filter.Text);
- }
- private void BtnAsc_Click(object sender, RoutedEventArgs e)
- {
- sortType = 0;
- GetData(Search.Text, Filter.Text);
- }
- private void BtnEdit_Click(object sender, RoutedEventArgs e)
- {
- Button btn = (Button)sender;
- int id = int.Parse(btn.Uid);
- FrameClass.FrameMain.Navigate(new CreateOrUpdate(id));
- }
- private void LVMaterials_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- if (LVMaterials.SelectedItems.Count >= 2)
- {
- BtnChangeMinCount.Visibility = Visibility.Visible;
- }
- else
- {
- BtnChangeMinCount.Visibility = Visibility.Hidden;
- }
- }
- private void BtnChangeMinCount_Click(object sender, RoutedEventArgs e)
- {
- List<Material> materials = new List<Material>();
- foreach (var item in LVMaterials.SelectedItems)
- {
- materials.Add((Material)item);
- }
- new ChangeMinCount(materials).Show();
- }
- private void BtnAddNew_Click(object sender, RoutedEventArgs e)
- {
- FrameClass.FrameMain.Navigate(new CreateOrUpdate());
- }
- private void ExportToWord_Click(object sender, RoutedEventArgs e)
- {
- var allUsers = BaseClass.Base.MaterialType.ToList();
- var allCategories = BaseClass.Base.Material.ToList();
- var application = new Word.Application();
- Word.Document document = application.Documents.Add();
- foreach (var Material in allUsers)
- {
- Word.Paragraph userParagraph = document.Paragraphs.Add();
- Word.Range userRange = userParagraph.Range;
- userParagraph.set_Style("Обычный");
- userRange.InsertParagraphAfter();
- Word.Paragraph tableParagraph = document.Paragraphs.Add();
- Word.Range tableRange = tableParagraph.Range;
- Word.Table matTable = document.Tables.Add(tableRange, allCategories.Count()+1, 3);
- matTable.Borders.InsideLineStyle = matTable.Borders.OutsideLineStyle = Word.WdLineStyle.wdLineStyleSingle;
- matTable.Range.Cells.VerticalAlignment = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
- Word.Range cellRange;
- cellRange = matTable.Cell(1, 1).Range;
- cellRange.Text = "Материал";
- cellRange = matTable.Cell(1, 2).Range;
- cellRange.Text = "ТипМатериала";
- cellRange = matTable.Cell(1, 3).Range;
- cellRange.Text = "нинаю";
- matTable.Rows[1].Range.Bold = 1;
- for (int i = 0; i < allCategories.Count(); i++)
- {
- var currentMaterial = allCategories[i];
- cellRange = matTable.Cell(i + 2, 2).Range;
- //Word.InlineShape imageShape = cellRange.InlineShapes.AddPicture(AppDomain.CurrentDomain.BaseDirectory + "..\\...\\" + currentMaterial.Image);
- cellRange = matTable.Cell(i + 2, 1).Range;
- cellRange.Text = currentMaterial.Title;
- }
- }
- document.SaveAs2(@"X:\bebra\Text1.docx");
- }
- }
- }
|