using System; using System.Collections.Generic; using System.Data.OleDb; using unesMdb.model; namespace unesMdb { public static class DbUtils { public static string ConnectionString; public static List CollectUsers() { List result = new List(); 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 CollectFlats(List users) { List result = new List(); 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; } public static void CollectLinks(List users) { List result = new List(); string sql = "select * from vuko"; 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())); if (user == null) { continue; } user.FeeId = reader["Konu"].ToString(); } } } catch (Exception x) { Console.WriteLine(x.Message); } } } public static List CollectFees(List users) { List result = new List(); string sql = "select * from vuri"; 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 => reader["Konu"].ToString().Equals(u.FeeId)); if (user == null) { continue; } var fee = new FeeData { Name = reader["Lani"].ToString(), Amount = reader["Masu"].ToString() }; user.Fees.Add(fee); } } } catch (Exception x) { Console.WriteLine(x.Message); } } return result; } } }