Skip to content

Commit

Permalink
The patch functionality is finished
Browse files Browse the repository at this point in the history
  • Loading branch information
TwinkmrMask committed Mar 16, 2022
1 parent 7254518 commit 53ea0d3
Show file tree
Hide file tree
Showing 15 changed files with 99 additions and 160 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -353,3 +353,4 @@ MigrationBackup/
*.xlsx
*links
*db
*/Resources/
21 changes: 6 additions & 15 deletions Program/ClassDiagram.cd
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<ClassDiagram MajorVersion="1" MinorVersion="1" GroupingSetting="Access" MembersFormat="FullSignature">
<Class Name="XmlParser.DataBase" Collapsed="true">
<Position X="3.75" Y="3.5" Width="1.5" />
<TypeIdentifier>
<HashCode>gAIAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAABAA=</HashCode>
<FileName>DataBase.cs</FileName>
</TypeIdentifier>
<Lollipop Position="0.2" />
</Class>
<Class Name="XmlParser.Content" Collapsed="true">
<Position X="6" Y="6" Width="1.5" />
<TypeIdentifier>
Expand All @@ -18,29 +10,28 @@
<Class Name="XmlParser.Handler" Collapsed="true">
<Position X="3.75" Y="6" Width="1.5" />
<TypeIdentifier>
<HashCode>AAIAAgQABACAIgAAACAAAAAAAAASUAACAAgAAACgAAA=</HashCode>
<HashCode>AAIAAoQABAAAIgAAACAAAAAIAAASUAAAAAgAAACgAAA=</HashCode>
<FileName>Handler.cs</FileName>
</TypeIdentifier>
</Class>
<Class Name="XmlParser.XmlAdapter" Collapsed="true">
<Position X="6" Y="3.5" Width="1.5" />
<Position X="5" Y="3.5" Width="1.5" />
<TypeIdentifier>
<HashCode>AAAAAAAAAAAAAAQAAAAAAQAACBAAQAgAACAAAAAAAAA=</HashCode>
<HashCode>AAAAAAAAAAAAAAQAAAAAAAAACBAAQAgAACAAAAAAAAA=</HashCode>
<FileName>xmlAdapter.cs</FileName>
</TypeIdentifier>
<Lollipop Position="0.2" />
</Class>
<Class Name="XmlParser.Platform" Collapsed="true">
<Position X="5" Y="2" Width="1.5" />
<TypeIdentifier>
<HashCode>AAAAAAkAACAAEgBAAAAAAAAAAgAgIABACAAAAAAAAAA=</HashCode>
<HashCode>AAAAoQsAACAgAgBAAAAAAAAAAgEgIABQCAAAAAAAAAA=</HashCode>
<FileName>Platform.cs</FileName>
</TypeIdentifier>
</Class>
<Class Name="XmlParser.MainWindow" Collapsed="true">
<Position X="11" Y="2" Width="1.5" />
<TypeIdentifier>
<HashCode>AAAIAAAAAAAAAAYIAAAAAAAAAgACAAABAAAFBBBAAAA=</HashCode>
<HashCode>AEAIAAAAAAAAAAYIAAAAAAAAAgADAAABAAGEBBAAAAA=</HashCode>
<FileName>MainWindow.xaml.cs</FileName>
</TypeIdentifier>
<Lollipop Orientation="Bottom" Position="0.235" />
Expand Down Expand Up @@ -69,7 +60,7 @@
<Interface Name="XmlParser.IDefaultSettings" Collapsed="true">
<Position X="8.75" Y="3.5" Width="1.5" />
<TypeIdentifier>
<HashCode>AAACAAAAAAACAAAAAAAAAwgAAAAAAACAAgAAAAAAAAA=</HashCode>
<HashCode>AAACAAAAAAACAAAAAAAAAgAAAAAAAACAAgAAAAAAAAA=</HashCode>
<FileName>IDefaultSettings.cs</FileName>
</TypeIdentifier>
</Interface>
Expand Down
51 changes: 0 additions & 51 deletions Program/ClassDiagram1.cd

This file was deleted.

37 changes: 16 additions & 21 deletions Program/Handler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,11 @@ internal class Handler

public Handler()
{
try
{
_grossWeightQuantity = 0;
_netWeightQuantity = 0;
_positions = 0;
_awb = new List<(string, string)>();
_data = new List<(string, string)>();
}
catch (Exception exception) { MessageBox.Show(exception.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); }
finally
{
this._grossWeightQuantity = default;
this._netWeightQuantity = default;
this._positions = default;
}
_grossWeightQuantity = 0;
_netWeightQuantity = 0;
_positions = 0;
_awb = new();
_data = new();
}

public List<(string, string)> XmlHandler(in string file)
Expand All @@ -49,7 +39,8 @@ public Handler()
if (File.Exists(file)) document.Load(file);
else document.LoadXml(file);
}
catch (Exception exp) { MessageBox.Show(exp.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); return new List<(string, string)>() { ("Файл повреждён", "Неудалось прочитать файл") }; }
catch (Exception exp) { MessageBox.Show(exp.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
return new List<(string, string)>() { ("Файл повреждён", "Неудалось прочитать файл") }; }

var book = Open();

Expand All @@ -70,7 +61,7 @@ public Handler()
break;
case "ESADout_CUConsigment":
foreach (XmlNode transport in info.ChildNodes)
foreach(XmlNode unused in transport)
foreach (XmlNode unused in transport)
Collect(Search("catESAD_cu:TransportIdentifier", info, "Транспорт"), book);
break;
case "ESADout_CUMainContractTerms":
Expand All @@ -82,14 +73,18 @@ public Handler()
Calc(Search("catESAD_cu:GrossWeightQuantity", info, "Масса брутто").Item2, ref _grossWeightQuantity);
Calc(Search("catESAD_cu:NetWeightQuantity", info, "Масса нетто").Item2, ref _netWeightQuantity);
break;
default:
break;
}

foreach (XmlNode product in info.ChildNodes)
{
foreach (XmlNode count in product.ChildNodes)
if (count.Name == "catESAD_cu:GoodsGroupInformation")
foreach (var about in count.Cast<XmlNode>().Where(about => about.Name == "catESAD_cu:GoodsGroupQuantity"))
Calc(Search("catESAD_cu:GoodsQuantity", about, "Количество товара").Item2, ref _positions);
}

foreach (XmlNode doc in info)
{
if (doc.Name == "ESADout_CUPresentedDocument")
Expand All @@ -103,15 +98,15 @@ public Handler()
}
}
}
}
}
Collect(("Общая масса брутто", this._grossWeightQuantity.ToString(CultureInfo.InvariantCulture)), book);
Collect(("Общая масса нетто", this._netWeightQuantity.ToString(CultureInfo.InvariantCulture)), book);
Collect(("Общая масса нетто", this._netWeightQuantity.ToString(CultureInfo.InvariantCulture)), book);
Collect(("Всего позиций", this._positions.ToString(CultureInfo.InvariantCulture)), book);
foreach (var pair in _awb.Distinct()) Collect(pair, book);
Close(book.Item1);
return this._data;
}

//auxiliary methods
private static void Close(IWorkbook wb)
{
Expand Down Expand Up @@ -163,6 +158,6 @@ private void Collect((string, string) value, (IWorkbook, ISheet) book)
Save(value, book);
}
private static bool Validation((string, string) value) => !string.IsNullOrWhiteSpace(value.Item1) || !string.IsNullOrWhiteSpace(value.Item2);

}
}
11 changes: 10 additions & 1 deletion Program/IDefaultSettings.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
using System.Collections.Generic;
using System.IO;

namespace XmlParser
{
public interface IDefaultSettings
{
const string DefaultPath = "../../../Resources/";
static string DefaultPath {
get
{
string path = "../../../Resources/";
if (!Directory.Exists(path))
Directory.CreateDirectory(path);
return path;
}
}
static string NameExcelFile => DefaultPath + "declarationInfo.xlsx";
static string IndexFileName => DefaultPath + "links";
static string DataFileName => DefaultPath + "db";
Expand Down
3 changes: 1 addition & 2 deletions Program/Information.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" Margin="0,0,0,49" HorizontalAlignment="Left" Width="614">
<TextBox x:Name="block" SelectionBrush="Transparent" BorderBrush="Transparent" BorderThickness="0,0,0,0"/>
</ScrollViewer>

<Button x:Name="OpenInExcel" Background="ForestGreen" Content="Открыть в MS Excel" HorizontalAlignment="Right" VerticalAlignment="Bottom" Height="44" Width="165" MouseEnter="OpenInExcel_MouseEnter" MouseLeave="OpenInExcel_MouseLeave" OpacityMask="Black" Click="OpenInExcel_Click" Margin="0,0,5,5" FontSize="16" FontWeight="Normal" FontStyle="Normal"/>
<Label x:Name="toolbar" Background="Transparent" Height="44" VerticalAlignment="Bottom" Content="" FontSize="20" HorizontalAlignment="Left" Width="614"/>
<Image x:Name="OpenInExcel" Source="/Resources/button.png" StretchDirection="UpOnly" HorizontalAlignment="Right" VerticalAlignment="Bottom" Height="372" Width="137" MouseEnter="OpenInExcel_MouseEnter" MouseLeave="OpenInExcel_MouseLeave" OpacityMask="Black" MouseLeftButtonDown="OpenInExcel_MouseLeftButtonDown"/>
</Grid>
</Window>
19 changes: 14 additions & 5 deletions Program/Information.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Windows;

namespace XmlParser
{
Expand All @@ -23,12 +24,20 @@ private void Print(IEnumerable<(string, string)> value)
}
private void OpenInExcel_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e) => ToolbarStatus("Открыть в MS Excel");
private void OpenInExcel_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e) => ToolbarStatus(null);
private void OpenInExcel_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
private void OpenInExcel_Click(object sender, System.Windows.RoutedEventArgs e)
{
var prc = new Process();
prc.StartInfo.FileName = @Path.GetFullPath(Handler.GetPath());
prc.StartInfo.UseShellExecute = true;
prc.Start();
try
{
var prc = new Process();
prc.StartInfo.FileName = @Path.GetFullPath(Handler.GetPath());
prc.StartInfo.UseShellExecute = true;
prc.Start();
}

catch
{
MessageBox.Show("Нет приложения для открытия этого файла", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
}
}
12 changes: 10 additions & 2 deletions Program/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,16 @@
<Label Content="Источник:" Margin="1,0,726,402" FontFamily="Comic Sans MS"/>
<Label x:Name="Source" Content="" Margin="99,0,567,402" FontFamily="Comic Sans MS"/>

<Button x:Name="Open" Margin="613,0,17,402" Click="Open_Click"/>
<Button x:Name="Change" Margin="438,0,192,402" Visibility="Hidden" Click="Change_Click"/>
<Button x:Name="Open" Content="Открыть базу данных" Margin="0,10,18,0" Click="Open_Click" HorizontalAlignment="Right" VerticalAlignment="Top" Height="22" RenderTransformOrigin="0.5,0.5" Width="155">
<Button.RenderTransform>
<TransformGroup>
<ScaleTransform ScaleX="1"/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform/>
</TransformGroup>
</Button.RenderTransform>
</Button>
<ScrollViewer Background="Transparent" Margin="0,37,0,0">
<DataGrid x:Name="Data" GridLinesVisibility="None" Background="White" RowBackground="Transparent" CanUserAddRows="False">
<DataGrid.Columns>
Expand Down
63 changes: 33 additions & 30 deletions Program/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public partial class MainWindow
private string _fileName;
private bool _dataBaseFlag = false;
private static void Copy(string text) => Clipboard.SetText(text);

//получает путь к обрабаываемому файлу
private static void GetPath(out string directoryName, out string fileName)
{
Expand All @@ -27,7 +27,7 @@ private static void GetPath(out string directoryName, out string fileName)
}
catch (Exception exception1)
{
if (MessageBox.Show( $"Ошибка - {exception1.HResult}\nНажмите OK чтобы скопировать код ошибки, или нажмите Отмена чтобы переписать самостоятельно",
if (MessageBox.Show($"Ошибка - {exception1.HResult}\nНажмите OK чтобы скопировать код ошибки, или нажмите Отмена чтобы переписать самостоятельно",
"Ошибка получения пути", MessageBoxButton.OKCancel,
MessageBoxImage.Error) == MessageBoxResult.OK)
Copy(exception1.HResult.ToString());
Expand Down Expand Up @@ -57,11 +57,11 @@ private void SetSource()
try
{
GetPath(out this._directoryName, out this._fileName);
if ( new[] { _directoryName, _fileName }.Any(string.IsNullOrWhiteSpace))
if (new[] { _directoryName, _fileName }.Any(string.IsNullOrWhiteSpace))
throw new IOException("Null path");
GetFile();
var declarations = _fileNames.Select(item => new Content
{ FileName = item }).ToList();
var declarations = _fileNames.Select(item => new Content
{ FileName = item }).ToList();
Data.ItemsSource = declarations;
}

Expand All @@ -84,43 +84,46 @@ private void Btn_Click(object sender, RoutedEventArgs e)
if (Data.SelectedItem is not Content path) return;
if (_dataBaseFlag)
{
using (XmlAdapter adapter = new())
{
string path1 = adapter.GetContent(path.FileName);
info = new(path1);
}
using XmlAdapter adapter = new();
string path1 = adapter.GetContent(path.FileName);
info = new(path1);
}
else
{
{
info = new(path.FileName);
AddFile(path.FileName);
}
info.Show();
}
private static void AddFile(string name)
{
using var reader = XmlReader.Create(name);
if (reader.IsEmptyElement) return;
using (XmlAdapter adapter = new())
{
string xml = "";
string filename = Path.GetFileName(name);
adapter.CreateLink(xml, filename);
}
using XmlAdapter adapter = new();
if (adapter.IsLinks(name))
return;

XmlDocument document = new();
document.Load(name);
XmlElement root = document.DocumentElement;

string xml = root.OuterXml;
string filename = Path.GetFileName(name);
adapter.CreateLink(xml, filename);
}
private void OpenFromDatabase()
{
_dataBaseFlag = _dataBaseFlag == false;

private List<Content> OpenFromDatabase()
{
List<Content> contents = new();
using (XmlAdapter @base = new()) {
var data = @base.GetAllFileNames();
if(data != default) contents.AddRange(data.Select(para => new Content { FileName = para }));
}
Data.ItemsSource = contents;
Data.Items.Refresh();
using XmlAdapter @base = new();
var data = @base.GetAllFileNames();
if (data != default) contents.AddRange(data.Select(para => new Content { FileName = para }));
return contents;
}
private void Open_Click(object sender, RoutedEventArgs e)
{
_dataBaseFlag = !_dataBaseFlag;
Data.ItemsSource = OpenData(_dataBaseFlag);
}
private void Change_Click(object sender, RoutedEventArgs e) {}
private void Open_Click(object sender, RoutedEventArgs e) => OpenFromDatabase();
private List<Content> OpenData(bool _dataBaseFlag) => _dataBaseFlag ? OpenFromDatabase() : OpenFromDirectory();
private List<Content> OpenFromDirectory() => _fileNames.Select(item => new Content { FileName = item }).ToList();
}
}
Loading

0 comments on commit 53ea0d3

Please sign in to comment.