initial commit

This commit is contained in:
2026-08-04 14:41:21 +03:00
parent 3cb8fcde60
commit 1a1d6186d8
101 changed files with 23239 additions and 0 deletions

54
Data/CategoryTreeData.cs Normal file
View File

@@ -0,0 +1,54 @@
using Microsoft.Data.SqlClient;
namespace Library;
public class CategoryTreeData
{
private readonly List<CategoryItemData> m_RootElements = new( );
public List<CategoryItemData> RootElements { get => m_RootElements; }
private readonly Dictionary<int,CategoryItemData> m_AllElements = new( );
public int GetRootID( )
{
if ( m_RootElements.Count == 0 )
return 0;
return m_RootElements[0].ID;
}
public CategoryItemData? FindCategory( int id )
{
if ( m_AllElements.TryGetValue( id , out CategoryItemData? value ) )
return value;
return null;
}
public void LoadCategoryTree( SqlConnection connection )
{
using SqlDataReader reader = new SQLBuilder( connection , "select id,idfat,label,ime_x,cnt,lis_txt from [select_razdeli]" )
.ExecuteReader( );
while ( reader.Read( ) )
{
CategoryItemData model = new( )
{
ID = reader.Int( "id" ) ,
ParentID = reader.Int( "idfat" ) ,
ElementCount = reader.Int( "cnt" ) ,
Depth = reader.Int( "label" ) ,
Name = reader.StringSafe( "ime_x" ).Trim( ),
Catego_opis = reader.StringSafe( "lis_txt" ).Trim( )
};
m_AllElements[model.ID] = model;
}
foreach ( CategoryItemData m in m_AllElements.Values )
{
if ( m_AllElements.TryGetValue( m.ParentID , out CategoryItemData? parent ) )
parent.Children.Add( m );
else
m_RootElements.Add( m );
}
}
}