87 lines
3.1 KiB
C#
87 lines
3.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data.OleDb;
|
|
using unesMdb.model;
|
|
|
|
namespace unesMdb
|
|
{
|
|
public class DbUtils
|
|
{
|
|
public static string ConnectionString;
|
|
|
|
public static List<UserData> CollectUsers()
|
|
{
|
|
List<UserData> result = new List<UserData>();
|
|
string sql = "select * from heti";
|
|
using (OleDbConnection connection = new OleDbConnection(ConnectionString))
|
|
{
|
|
OleDbCommand command = new OleDbCommand(sql, connection);
|
|
try
|
|
{
|
|
connection.Open();
|
|
using (OleDbDataReader reader = command.ExecuteReader())
|
|
{
|
|
while (reader.Read())
|
|
{
|
|
result.Add(new UserData
|
|
{
|
|
Id = reader["Henu"].ToString(),
|
|
Name = reader["Heni"].ToString(),
|
|
Pin = reader["Hetu"].ToString()
|
|
});
|
|
}
|
|
}
|
|
}
|
|
catch (Exception x)
|
|
{
|
|
Console.WriteLine(x.Message);
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
public static List<FlatData> CollectFlats(List<UserData> users)
|
|
{
|
|
List<FlatData> result = new List<FlatData>();
|
|
string sql = "select * from huos";
|
|
using (OleDbConnection connection = new OleDbConnection(ConnectionString))
|
|
{
|
|
OleDbCommand command = new OleDbCommand(sql, connection);
|
|
try
|
|
{
|
|
connection.Open();
|
|
using (OleDbDataReader reader = command.ExecuteReader())
|
|
{
|
|
while (reader.Read())
|
|
{
|
|
var user = users.Find(u => u.Id.Equals(reader["Henu"].ToString()));
|
|
var existing = result.Find(f => f.Title.Equals(reader["Huno"].ToString()));
|
|
if (existing != null)
|
|
{
|
|
if (user != null)
|
|
{
|
|
existing.Users.Add(user);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
var flat = new FlatData { Id = reader["Hutu"].ToString(), Title = reader["Huno"].ToString() };
|
|
if (user != null)
|
|
{
|
|
flat.Users.Add(user);
|
|
}
|
|
result.Add(flat);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception x)
|
|
{
|
|
Console.WriteLine(x.Message);
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
}
|
|
}
|