-
Notifications
You must be signed in to change notification settings - Fork 1
/
prikrutilEFCoreInMemoryDB.cs
144 lines (114 loc) · 5.13 KB
/
prikrutilEFCoreInMemoryDB.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.Extensions.Options;
using saldoInMemory;
List<Room> rooms = [
new(1,10),
new(2,20),
new(3,30)
];
List<Tariff> tariffs = [
new(2024, 5, 5m),
new(2024, 7, 8m)
];
foreach (var r in rooms)
{
PrintReport(r, tariffs, new DateTime(2024, 4, 1), new DateTime(2024, 8, 1));
Console.WriteLine();
Console.WriteLine();
}
static void PrintReport(Room r, List<Tariff> tariffs, DateTime periodFrom, DateTime periodTo)
{
Console.WriteLine($"Комната №{r.Number}");
const int sh = 15;
Console.WriteLine("----------------------------------------------------------------------------------------------------------------------------------------------------");
Console.WriteLine($"|{" Период ",-sh}|{" Сальдо входящее ",-sh}|{" Начислено ",-sh}|{" Перерасчет ",-sh}|{" Итого начислено ",-sh}|{" Оплачено ",-sh}|{" Сальдо исходящее ",-sh}|");
Console.WriteLine("----------------------------------------------------------------------------------------------------------------------------------------------------");
decimal saldo_init = 0, itogo_nachisl = 0, saldo_out = 0;
/////////////////////////////////////////////////
var optio1 = new DbContextOptionsBuilder<saldoItems>().UseInMemoryDatabase(databaseName: "saldo_vedomos").Options;
////////////////////////////////////////////////////////////////////////////////////////
using (var contextt1 = new saldoItems(optio1))
{
do
{
var actualTariff = tariffs.OrderByDescending(t => t.StartDt).FirstOrDefault(t => t.StartDt <= periodFrom);
if (actualTariff == null)
{
Console.WriteLine($"|{periodFrom,-sh:MMMMyyyy}|{"-",sh}|{"-",sh}|{"-",sh}|{"-",sh}|{"-",sh}|{"-",sh}|");
}
else
{
Pereraschet_room recount = new(-1);
Oplata_room payment = new(5);//payment.opl_am //r.Number
itogo_nachisl = actualTariff.Amount * r.Square + recount.perer_am;
saldo_out = saldo_init + itogo_nachisl - payment.opl_am;
Console.WriteLine($"|{periodFrom,-sh:MMMMyyyy}|{saldo_init,sh}|{(actualTariff.Amount * r.Square),sh}|{recount.perer_am,sh}|{itogo_nachisl,sh}|{payment.opl_am,sh}|{saldo_out,sh}|");
saldo_init = saldo_out;
//////////////////////////////////////////////////////////////////
var saldrow0 = new saldoRow
{
perio = periodFrom.Month.ToString(),
saldoIncome = saldo_init,
nachisleno = actualTariff.Amount * r.Square,
perer = recount.perer_am,
itogoNach = itogo_nachisl,
oplach = payment.opl_am,
saldoOutcome = saldo_out
};
contextt1.saldoRows.Add(saldrow0);
contextt1.SaveChanges();
}
periodFrom = periodFrom.AddMonths(1); //increment cikla
}
while (periodFrom <= periodTo);
}
Console.WriteLine("----------------------------------------------------------------------------------------------------------------------------------------------------");
}
public class Room(uint number, decimal square)
{
public uint Number { get; private set; } = number;
public decimal Square { get; private set; } = square;
public override string ToString()
{
return $"Номер комнаты - {Number} | Площадь комнаты - {Square}";
}
}
public class Tariff(int year, int month, decimal amount)
{
public string Code => StartDt.ToString("ddMMyyyy");
public DateTime StartDt { get; private set; } = new DateTime(year, month, 1);
public decimal Amount { get; private set; } = amount;
public override string ToString()
{
return $"Код тарифа - {Code} | Дата старта тарифа - {StartDt:yyy.MM.dd}";
}
}
public class Oplata_room(decimal oplata_amount) //uint room_number,
{
public decimal opl_am { get; private set; } = oplata_amount;
}
public class Pereraschet_room(decimal perer_amount)
{
public decimal perer_am { get; private set; } = perer_amount;
}
namespace saldoInMemory
{
public class saldoItems : DbContext
{
public saldoItems(DbContextOptions<saldoItems> options) : base(options) { } //konstruktor
public DbSet<saldoRow> saldoRows { get; set; }
}
public class saldoRow
{
public int saldoRowId { get; set; }
public string perio { get; set; }
public decimal saldoIncome { get; set; }
public decimal nachisleno { get; set; }
public decimal perer { get; set; }
public decimal itogoNach { get; set; }
public decimal oplach { get; set; }
public decimal saldoOutcome { get; set; }
}
}