From b5688b9b94db59d740482d371bed292bbee1a12d Mon Sep 17 00:00:00 2001 From: "Georgy.Khatuncev" Date: Fri, 20 Sep 2024 10:51:24 +0500 Subject: [PATCH] Move entity schema Move classes for work with DB in root dir. Fix problems with num cycles, after change to Enum --- DbCycleVDP/DbFurnace.cs | 24 ++++++++++++++++++ .../Db/DbCycle.cs => DbCycleVDP/TableCycle.cs | 4 +-- GenCycleVDP/Db/DbFurnace.cs | 23 ----------------- GenCycleVDP/GenCycle.cs | 25 +++++++++---------- GenCycleVDP/GenCycleVDP.csproj | 5 ++++ GenCycleVDP/Program.cs | 1 - GenCycleVDP/Resources/CycleStatus.cs | 2 +- 7 files changed, 44 insertions(+), 40 deletions(-) create mode 100644 DbCycleVDP/DbFurnace.cs rename GenCycleVDP/Db/DbCycle.cs => DbCycleVDP/TableCycle.cs (92%) delete mode 100644 GenCycleVDP/Db/DbFurnace.cs diff --git a/DbCycleVDP/DbFurnace.cs b/DbCycleVDP/DbFurnace.cs new file mode 100644 index 0000000..8941433 --- /dev/null +++ b/DbCycleVDP/DbFurnace.cs @@ -0,0 +1,24 @@ +using System; +using Microsoft.EntityFrameworkCore; + +namespace DbCycleVDP +{ + public class DbFurnace : DbContext + { + public DbSet Cycles { get; set; } + public DbFurnace() + { + Database.EnsureCreated(); + } + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { +// optionsBuilder.UseMySql("server=127.0.0.1;user=diplom;password=diplom;database=VDPCycles;", new MySqlServerVersion(new Version(8, 0))); + optionsBuilder.UseMySql("server=37.79.216.218;user=mytest;password=mytest;database=VDPCycles;", new MySqlServerVersion(new Version(8, 0))); + } + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + + } + } +} diff --git a/GenCycleVDP/Db/DbCycle.cs b/DbCycleVDP/TableCycle.cs similarity index 92% rename from GenCycleVDP/Db/DbCycle.cs rename to DbCycleVDP/TableCycle.cs index 56456b2..7246b25 100644 --- a/GenCycleVDP/Db/DbCycle.cs +++ b/DbCycleVDP/TableCycle.cs @@ -2,10 +2,10 @@ using System.ComponentModel.DataAnnotations.Schema; using System.ComponentModel.DataAnnotations; -namespace GenCycleVDP.Db +namespace DbCycleVDP { [Table("Cycles")] - internal class DbCycle + public class TableCycle { [Column("idCycle"), Required, Key] public int IdCycle { get; set; } diff --git a/GenCycleVDP/Db/DbFurnace.cs b/GenCycleVDP/Db/DbFurnace.cs deleted file mode 100644 index 4d2d1f2..0000000 --- a/GenCycleVDP/Db/DbFurnace.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore; - -namespace GenCycleVDP.Db -{ - internal class DbFurnace : DbContext - { - public DbSet Cycles { get; set; } - public DbFurnace() - { - Database.EnsureCreated(); - } - protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) - { - optionsBuilder.UseMySql("server=127.0.0.1;user=diplom;password=diplom;database=VDPCycles;", new MySqlServerVersion(new Version(8, 0))); - } - - protected override void OnModelCreating(ModelBuilder modelBuilder) - { - - } - } -} diff --git a/GenCycleVDP/GenCycle.cs b/GenCycleVDP/GenCycle.cs index f0340d9..d0486e6 100644 --- a/GenCycleVDP/GenCycle.cs +++ b/GenCycleVDP/GenCycle.cs @@ -2,6 +2,7 @@ using System.Linq; using System.Threading.Tasks; using GenCycleVDP.Resources; +using DbCycleVDP; namespace GenCycleVDP { @@ -78,7 +79,7 @@ namespace GenCycleVDP { try { - using var db = new Db.DbFurnace(); + using var db = new DbFurnace(); var tmp = (from u in db.Cycles where u.NumVdp == vdp @@ -122,19 +123,17 @@ namespace GenCycleVDP { try { - using (var db = new Db.DbFurnace()) + using var db = new DbFurnace(); + var tmp = new TableCycle() { - var tmp = new Db.DbCycle() - { - NumVdp = vdp, - NumCycle = (int)currCycle, - FactStart = factStart, - FactEnd = factEnd, - ThinkEnd = thinkEnd - }; - db.Cycles.Add(tmp); - db.SaveChanges(); - } + NumVdp = vdp, + NumCycle = (int)currCycle, + FactStart = factStart, + FactEnd = factEnd, + ThinkEnd = thinkEnd + }; + db.Cycles.Add(tmp); + db.SaveChanges(); } catch (Exception e) { diff --git a/GenCycleVDP/GenCycleVDP.csproj b/GenCycleVDP/GenCycleVDP.csproj index 6942e31..4902e2e 100644 --- a/GenCycleVDP/GenCycleVDP.csproj +++ b/GenCycleVDP/GenCycleVDP.csproj @@ -7,6 +7,11 @@ enable + + + + + diff --git a/GenCycleVDP/Program.cs b/GenCycleVDP/Program.cs index a6787c1..864eaa9 100644 --- a/GenCycleVDP/Program.cs +++ b/GenCycleVDP/Program.cs @@ -17,7 +17,6 @@ namespace GenCycleVDP a.Start(); tasks.Add(a); } - Task.Delay(1000 * 5).Wait(); int count = 0; while (!isExiting) diff --git a/GenCycleVDP/Resources/CycleStatus.cs b/GenCycleVDP/Resources/CycleStatus.cs index 1546aa9..aea3eaa 100644 --- a/GenCycleVDP/Resources/CycleStatus.cs +++ b/GenCycleVDP/Resources/CycleStatus.cs @@ -1,6 +1,6 @@ namespace GenCycleVDP.Resources { - public enum CycleStatus : ushort + public enum CycleStatus : int { EndTechCycle = 0, LoadUnload = 1,