This commit is contained in:
sardq 2024-05-13 21:44:31 +04:00
parent 3699d306cf
commit 40006ab511
20 changed files with 847 additions and 294 deletions

View File

@ -11,7 +11,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SYBDContracts", "SYBDContra
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SYBDBusinessLogic", "SYBDBusinessLogic\SYBDBusinessLogic.csproj", "{F653B97F-956A-4533-A54D-6EB96AEAD388}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SYBDDatabaseImplement", "SYBDDatabaseImplement\SYBDDatabaseImplement.csproj", "{9EDE2CAB-922C-40EB-8B8B-CD69502EEC66}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SYBDDatabaseImplement", "SYBDDatabaseImplement\SYBDDatabaseImplement.csproj", "{9EDE2CAB-922C-40EB-8B8B-CD69502EEC66}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SYBDMongoDB", "SYBDMongoDB\SYBDMongoDB.csproj", "{ACE86B38-7C84-4B50-B204-8375815B3C6C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -39,6 +41,10 @@ Global
{9EDE2CAB-922C-40EB-8B8B-CD69502EEC66}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9EDE2CAB-922C-40EB-8B8B-CD69502EEC66}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9EDE2CAB-922C-40EB-8B8B-CD69502EEC66}.Release|Any CPU.Build.0 = Release|Any CPU
{ACE86B38-7C84-4B50-B204-8375815B3C6C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{ACE86B38-7C84-4B50-B204-8375815B3C6C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{ACE86B38-7C84-4B50-B204-8375815B3C6C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{ACE86B38-7C84-4B50-B204-8375815B3C6C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -11,8 +11,8 @@ using SYBDDatabaseImplement;
namespace SYBDDatabaseImplement.Migrations
{
[DbContext(typeof(SYBDDatabase))]
[Migration("20240416144856_InitialCreate")]
partial class InitialCreate
[Migration("20240513164530_init")]
partial class init
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
@ -41,7 +41,7 @@ namespace SYBDDatabaseImplement.Migrations
b.HasKey("Id");
b.ToTable("Autos");
b.ToTable("auto");
});
modelBuilder.Entity("SYBDDatabaseImplement.Models.Client", b =>
@ -66,7 +66,7 @@ namespace SYBDDatabaseImplement.Migrations
b.HasKey("Id");
b.ToTable("Clients");
b.ToTable("client");
});
modelBuilder.Entity("SYBDDatabaseImplement.Models.Insurance", b =>
@ -91,7 +91,7 @@ namespace SYBDDatabaseImplement.Migrations
b.HasKey("Id");
b.ToTable("Insurances");
b.ToTable("insurance");
});
modelBuilder.Entity("SYBDDatabaseImplement.Models.Order", b =>
@ -118,8 +118,9 @@ namespace SYBDDatabaseImplement.Migrations
b.Property<double>("Price")
.HasColumnType("double precision");
b.Property<int>("Status")
.HasColumnType("integer");
b.Property<string>("Status")
.IsRequired()
.HasColumnType("text");
b.Property<int>("WorkerId")
.HasColumnType("integer");
@ -134,7 +135,7 @@ namespace SYBDDatabaseImplement.Migrations
b.HasIndex("WorkerId");
b.ToTable("Orders");
b.ToTable("order");
});
modelBuilder.Entity("SYBDDatabaseImplement.Models.Worker", b =>
@ -158,7 +159,7 @@ namespace SYBDDatabaseImplement.Migrations
b.HasKey("Id");
b.ToTable("Workers");
b.ToTable("worker");
});
modelBuilder.Entity("SYBDDatabaseImplement.Models.Order", b =>

View File

@ -5,12 +5,12 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace SYBDDatabaseImplement.Migrations
{
public partial class InitialCreate : Migration
public partial class init : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Autos",
name: "auto",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
@ -20,11 +20,11 @@ namespace SYBDDatabaseImplement.Migrations
},
constraints: table =>
{
table.PrimaryKey("PK_Autos", x => x.Id);
table.PrimaryKey("PK_auto", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Clients",
name: "client",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
@ -35,11 +35,11 @@ namespace SYBDDatabaseImplement.Migrations
},
constraints: table =>
{
table.PrimaryKey("PK_Clients", x => x.Id);
table.PrimaryKey("PK_client", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Insurances",
name: "insurance",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
@ -50,11 +50,11 @@ namespace SYBDDatabaseImplement.Migrations
},
constraints: table =>
{
table.PrimaryKey("PK_Insurances", x => x.Id);
table.PrimaryKey("PK_insurance", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Workers",
name: "worker",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
@ -65,11 +65,11 @@ namespace SYBDDatabaseImplement.Migrations
},
constraints: table =>
{
table.PrimaryKey("PK_Workers", x => x.Id);
table.PrimaryKey("PK_worker", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Orders",
name: "order",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
@ -80,74 +80,74 @@ namespace SYBDDatabaseImplement.Migrations
WorkerId = table.Column<int>(type: "integer", nullable: false),
Price = table.Column<double>(type: "double precision", nullable: false),
Description = table.Column<string>(type: "text", nullable: false),
Status = table.Column<int>(type: "integer", nullable: false)
Status = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Orders", x => x.Id);
table.PrimaryKey("PK_order", x => x.Id);
table.ForeignKey(
name: "FK_Orders_Autos_AutoId",
name: "FK_order_auto_AutoId",
column: x => x.AutoId,
principalTable: "Autos",
principalTable: "auto",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Orders_Clients_ClientId",
name: "FK_order_client_ClientId",
column: x => x.ClientId,
principalTable: "Clients",
principalTable: "client",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Orders_Insurances_InsuranceId",
name: "FK_order_insurance_InsuranceId",
column: x => x.InsuranceId,
principalTable: "Insurances",
principalTable: "insurance",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Orders_Workers_WorkerId",
name: "FK_order_worker_WorkerId",
column: x => x.WorkerId,
principalTable: "Workers",
principalTable: "worker",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_Orders_AutoId",
table: "Orders",
name: "IX_order_AutoId",
table: "order",
column: "AutoId");
migrationBuilder.CreateIndex(
name: "IX_Orders_ClientId",
table: "Orders",
name: "IX_order_ClientId",
table: "order",
column: "ClientId");
migrationBuilder.CreateIndex(
name: "IX_Orders_InsuranceId",
table: "Orders",
name: "IX_order_InsuranceId",
table: "order",
column: "InsuranceId");
migrationBuilder.CreateIndex(
name: "IX_Orders_WorkerId",
table: "Orders",
name: "IX_order_WorkerId",
table: "order",
column: "WorkerId");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Orders");
name: "order");
migrationBuilder.DropTable(
name: "Autos");
name: "auto");
migrationBuilder.DropTable(
name: "Clients");
name: "client");
migrationBuilder.DropTable(
name: "Insurances");
name: "insurance");
migrationBuilder.DropTable(
name: "Workers");
name: "worker");
}
}
}

View File

@ -39,7 +39,7 @@ namespace SYBDDatabaseImplement.Migrations
b.HasKey("Id");
b.ToTable("Autos");
b.ToTable("auto");
});
modelBuilder.Entity("SYBDDatabaseImplement.Models.Client", b =>
@ -64,7 +64,7 @@ namespace SYBDDatabaseImplement.Migrations
b.HasKey("Id");
b.ToTable("Clients");
b.ToTable("client");
});
modelBuilder.Entity("SYBDDatabaseImplement.Models.Insurance", b =>
@ -89,7 +89,7 @@ namespace SYBDDatabaseImplement.Migrations
b.HasKey("Id");
b.ToTable("Insurances");
b.ToTable("insurance");
});
modelBuilder.Entity("SYBDDatabaseImplement.Models.Order", b =>
@ -116,8 +116,9 @@ namespace SYBDDatabaseImplement.Migrations
b.Property<double>("Price")
.HasColumnType("double precision");
b.Property<int>("Status")
.HasColumnType("integer");
b.Property<string>("Status")
.IsRequired()
.HasColumnType("text");
b.Property<int>("WorkerId")
.HasColumnType("integer");
@ -132,7 +133,7 @@ namespace SYBDDatabaseImplement.Migrations
b.HasIndex("WorkerId");
b.ToTable("Orders");
b.ToTable("order");
});
modelBuilder.Entity("SYBDDatabaseImplement.Models.Worker", b =>
@ -156,7 +157,7 @@ namespace SYBDDatabaseImplement.Migrations
b.HasKey("Id");
b.ToTable("Workers");
b.ToTable("worker");
});
modelBuilder.Entity("SYBDDatabaseImplement.Models.Order", b =>

View File

@ -3,12 +3,15 @@ using SYBDContracts.ViewModels;
using SYBDDataModels.Models;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;
namespace SYBDDatabaseImplement.Models
{
public class Auto : IAutoModel
{
public int Id { get; private set; }
[BsonRepresentation(BsonType.Int32)]
public int Id { get; set; }
[Required]
public string Model { get; private set; } = string.Empty;
@ -57,5 +60,14 @@ namespace SYBDDatabaseImplement.Models
Model = Model,
StateNumber = StateNumber
};
}
public Auto (AutoViewModel model)
{
Id = model.Id;
Model = model.Model;
StateNumber = model.StateNumber;
}
public Auto()
{
}
}
}

View File

@ -1,4 +1,6 @@
using SYBDContracts.BindingModels;
using MongoDB.Bson.Serialization.Attributes;
using MongoDB.Bson;
using SYBDContracts.BindingModels;
using SYBDContracts.ViewModels;
using SYBDDataModels.Models;
using System.ComponentModel.DataAnnotations;
@ -8,7 +10,8 @@ namespace SYBDDatabaseImplement.Models
{
public class Client : IClientModel
{
public int Id { get; private set; }
[BsonRepresentation(BsonType.Int32)]
public int Id { get; set; }
[Required]
public string Fullname { get; private set; } = string.Empty;
@ -62,5 +65,15 @@ namespace SYBDDatabaseImplement.Models
Phone = Phone,
Email = Email,
};
}
public Client(ClientViewModel model)
{
Id = model.Id;
Fullname = model.Fullname;
Phone = model.Phone;
Email = model.Email;
}
public Client()
{
}
}
}

View File

@ -1,4 +1,6 @@
using SYBDContracts.BindingModels;
using MongoDB.Bson.Serialization.Attributes;
using MongoDB.Bson;
using SYBDContracts.BindingModels;
using SYBDContracts.ViewModels;
using SYBDDataModels.Models;
using System.ComponentModel.DataAnnotations;
@ -8,7 +10,8 @@ namespace SYBDDatabaseImplement.Models
{
public class Insurance : IInsuranceModel
{
public int Id { get; private set; }
[BsonRepresentation(BsonType.Int32)]
public int Id { get; set; }
[Required]
public string Name { get; private set; } = string.Empty;
@ -64,5 +67,15 @@ namespace SYBDDatabaseImplement.Models
Address = Address,
Phone = Phone,
};
}
public Insurance(InsuranceViewModel model)
{
Id = model.Id;
Name = model.Name;
Address = model.Address;
Phone = model.Phone;
}
public Insurance()
{
}
}
}

View File

@ -1,7 +1,12 @@
using SYBDContracts.BindingModels;
using MongoDB.Bson.Serialization.Attributes;
using MongoDB.Bson;
using SYBDContracts.BindingModels;
using SYBDContracts.ViewModels;
using SYBDDataModels.Models;
using System.ComponentModel.DataAnnotations;
using System.Net;
using System.Numerics;
using System.Xml.Linq;
namespace SYBDDatabaseImplement.Models
{
@ -22,8 +27,8 @@ namespace SYBDDatabaseImplement.Models
public string Description { get; private set; } = string.Empty;
[Required]
public string Status { get; set; }
public int Id { get; set; }
[BsonRepresentation(BsonType.Int32)]
public int Id { get; set; }
public virtual Auto Auto { get; set; }
public virtual Client Client { get; set; }
@ -69,5 +74,19 @@ namespace SYBDDatabaseImplement.Models
Status = Status,
Id = Id,
};
}
public Order(OrderViewModel model)
{
AutoId = model.AutoId;
ClientId = model.ClientId;
InsuranceId = model.InsuranceId;
WorkerId = model.WorkerId;
Price = model.Price;
Description = model.Description;
Status = model.Status;
Id = model.Id;
}
public Order()
{
}
}
}

View File

@ -0,0 +1,18 @@
using SYBDContracts.BindingModels;
using SYBDContracts.ViewModels;
using SYBDDataModels.Models;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;
namespace SYBDDatabaseImplement.Models
{
public class Sequence
{
[BsonRepresentation(BsonType.String)]
public string Id { get; set; }
public int Count { get; set; }
}
}

View File

@ -1,14 +1,19 @@
using SYBDContracts.BindingModels;
using MongoDB.Bson.Serialization.Attributes;
using MongoDB.Bson;
using SYBDContracts.BindingModels;
using SYBDContracts.ViewModels;
using SYBDDataModels.Models;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Numerics;
using System.Xml.Linq;
namespace SYBDDatabaseImplement.Models
{
public class Worker : IWorkerModel
{
public int Id { get; set; }
[BsonRepresentation(BsonType.Int32)]
public int Id { get; set; }
[Required]
public string Fullname { get; set; } = string.Empty;
@ -54,5 +59,15 @@ namespace SYBDDatabaseImplement.Models
Address = Address,
Salary = Salary
};
}
public Worker(WorkerViewModel model)
{
Id = model.Id;
Fullname = model.Fullname;
Address = model.Address;
Salary = model.Salary;
}
public Worker()
{
}
}
}

View File

@ -1,5 +1,6 @@
using SYBDDatabaseImplement.Models;
using Microsoft.EntityFrameworkCore;
using Npgsql;
namespace SYBDDatabaseImplement
{
@ -9,12 +10,16 @@ namespace SYBDDatabaseImplement
{
if (optionsBuilder.IsConfigured == false)
{
optionsBuilder.UseNpgsql(@"Host=192.168.225.184;Database=postgres;Username=sardq;");
optionsBuilder.UseNpgsql(@"Host=192.168.50.49;Database=postgres;Username=postgres;");
}
base.OnConfiguring(optionsBuilder);
}
private NpgsqlConnection GetConnection()
{
return new NpgsqlConnection("Host=192.168.50.49;Database=postgres;Username=postgres;");
}
public virtual DbSet<Auto> auto { set; get; }
public virtual DbSet<Auto> auto { set; get; }
public virtual DbSet<Client> client { set; get; }
@ -22,5 +27,93 @@ namespace SYBDDatabaseImplement
public virtual DbSet<Order> order { set; get; }
public virtual DbSet<Worker> worker { set; get; }
}
public List<Sequence> GetSequences()
{
List<Sequence> sequences = new List<Sequence>();
{
using var conn = GetConnection();
conn.Open();
using var cmd = new NpgsqlCommand("SELECT sequencename, last_value " +
"FROM pg_sequences " +
"WHERE sequencename = 'worker_id_seq'", conn);
using var reader = cmd.ExecuteReader();
if (reader.Read())
{
sequences.Add(new Sequence
{
Id = "worker",
Count = reader.GetInt32(1)
});
}
}
{
using var conn = GetConnection();
conn.Open();
using var cmd = new NpgsqlCommand("SELECT sequencename, last_value " +
"FROM pg_sequences " +
"WHERE sequencename = 'auto_id_seq'", conn);
using var reader = cmd.ExecuteReader();
if (reader.Read())
{
sequences.Add(new Sequence
{
Id = "auto",
Count = reader.GetInt32(1)
});
}
}
{
using var conn = GetConnection();
conn.Open();
using var cmd = new NpgsqlCommand("SELECT sequencename, last_value " +
"FROM pg_sequences " +
"WHERE sequencename = 'client_id_seq'", conn);
using var reader = cmd.ExecuteReader();
if (reader.Read())
{
sequences.Add(new Sequence
{
Id = "client",
Count = reader.GetInt32(1)
});
}
}
{
using var conn = GetConnection();
conn.Open();
using var cmd = new NpgsqlCommand("SELECT sequencename, last_value " +
"FROM pg_sequences " +
"WHERE sequencename = 'insurance_id_seq'", conn);
using var reader = cmd.ExecuteReader();
if (reader.Read())
{
sequences.Add(new Sequence
{
Id = "insurance",
Count = reader.GetInt32(1)
});
}
}
{
using var conn = GetConnection();
conn.Open();
using var cmd = new NpgsqlCommand("SELECT sequencename, last_value " +
"FROM pg_sequences " +
"WHERE sequencename = 'order_id_seq'", conn);
using var reader = cmd.ExecuteReader();
if (reader.Read())
{
sequences.Add(new Sequence
{
Id = "order",
Count = reader.GetInt32(1)
});
}
}
return sequences;
}
}
}

View File

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
@ -13,6 +13,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="MongoDB.Driver" Version="2.25.0" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="6.0.22" />
</ItemGroup>

View File

@ -0,0 +1,203 @@
using SYBDDatabaseImplement.Models;
using MongoDB.Driver;
using MongoDB.StorageModel;
using SYBDContracts.ViewModels;
namespace SYBDDatabaseImplement
{
public class ImplementationMongoDB : StorageModel
{
private IMongoDatabase _database;
private IMongoCollection<Auto> _autoCollection;
private IMongoCollection<Client> _clientCollection;
private IMongoCollection<Insurance> _insuranceCollection;
private IMongoCollection<Order> _OrderCollection;
private IMongoCollection<Worker> _WorkerCollection;
private IMongoCollection<Sequence> _sequenceCollection;
public ImplementationMongoDB()
{
var client = new MongoClient("mongodb://localhost:27017");
_database = client.GetDatabase("Autoservice");
_autoCollection = _database.GetCollection<Auto>("auto");
_clientCollection = _database.GetCollection<Client>("client");
_insuranceCollection = _database.GetCollection<Insurance>("insurance");
_OrderCollection = _database.GetCollection<Order>("Order");
_WorkerCollection = _database.GetCollection<Worker>("worker");
_sequenceCollection = _database.GetCollection<Sequence>("sequence");
}
// auto
public override void AddAuto(AutoViewModel auto)
{
if (auto.Id == 0)
{
Sequence sequence = _sequenceCollection.Find(seq => seq.Id == "auto").FirstOrDefault();
sequence.Count++;
auto.Id = sequence.Count;
_sequenceCollection.ReplaceOne(seq => seq.Id == "auto", sequence);
}
_autoCollection.InsertOne(new Auto(auto));
}
public override List<Auto> GetAutos()
{
return _autoCollection.Find(_ => true).ToList();
}
public override Auto GetAutoById(int id)
{
return _autoCollection.Find(auto => auto.Id == id).FirstOrDefault();
}
public override void UpdateAuto(Auto auto)
{
_autoCollection.ReplaceOne(c => c.Id == auto.Id, auto);
}
public override void DeleteAuto(int id)
{
_autoCollection.DeleteOne(auto => auto.Id == id);
}
// Client
public override void AddClient(ClientViewModel client)
{
if (client.Id == 0)
{
Sequence sequence = _sequenceCollection.Find(seq => seq.Id == "client").FirstOrDefault();
sequence.Count++;
client.Id = sequence.Count;
_sequenceCollection.ReplaceOne(seq => seq.Id == "client", sequence);
}
_clientCollection.InsertOne(new Client(client));
}
public override List<Client> GetClients()
{
return _clientCollection.Find(_ => true).ToList();
}
public override Client GetClientById(int id)
{
return _clientCollection.Find(client => client.Id == id).FirstOrDefault();
}
public override void UpdateClient(Client client)
{
_clientCollection.ReplaceOne(c => c.Id == client.Id, client);
}
public override void DeleteClient(int id)
{
_clientCollection.DeleteOne(client => client.Id == id);
}
// Insurance
public override void AddInsurance(InsuranceViewModel insurance)
{
if (insurance.Id == 0)
{
Sequence sequence = _sequenceCollection.Find(seq => seq.Id == "insurance").FirstOrDefault();
sequence.Count++;
insurance.Id = sequence.Count;
_sequenceCollection.ReplaceOne(seq => seq.Id == "insurance", sequence);
}
_insuranceCollection.InsertOne(new Insurance(insurance));
}
public override List<Insurance> GetInsurances()
{
return _insuranceCollection.Find(_ => true).ToList();
}
public override Insurance GetInsuranceById(int id)
{
return _insuranceCollection.Find(insurance => insurance.Id == id).FirstOrDefault();
}
public override void UpdateInsurance(Insurance insurance)
{
_insuranceCollection.ReplaceOne(r => r.Id == insurance.Id, insurance);
}
public override void DeleteInsurance(int id)
{
_insuranceCollection.DeleteOne(insurance => insurance.Id == id);
}
// Order
public override void AddOrder(OrderViewModel Order)
{
if (Order.Id == 0)
{
Sequence sequence = _sequenceCollection.Find(seq => seq.Id == "order").FirstOrDefault();
sequence.Count++;
Order.Id = sequence.Count;
_sequenceCollection.ReplaceOne(seq => seq.Id == "order", sequence);
}
_OrderCollection.InsertOne(new Order(Order));
}
public override List<Order> GetOrders()
{
return _OrderCollection.Find(_ => true).ToList();
}
public override Order GetOrderById(int id)
{
return _OrderCollection.Find(model => model.Id == id).FirstOrDefault();
}
public override void UpdateOrder(Order Order)
{
_OrderCollection.ReplaceOne(m => m.Id == Order.Id, Order);
}
public override void DeleteOrder(int id)
{
_OrderCollection.DeleteOne(model => model.Id == id);
}
// Worker
public override void AddWorker(WorkerViewModel Worker)
{
if (Worker.Id == 0)
{
Sequence sequence = _sequenceCollection.Find(seq => seq.Id == "Worker").FirstOrDefault();
sequence.Count++;
Worker.Id = sequence.Count;
_sequenceCollection.ReplaceOne(seq => seq.Id == "Worker", sequence);
}
_WorkerCollection.InsertOne(new Worker(Worker));
}
public override List<Worker> GetWorkeres()
{
return _WorkerCollection.Find(_ => true).ToList();
}
public override Worker GetWorkerById(int id)
{
return _WorkerCollection.Find(Worker => Worker.Id == id).FirstOrDefault();
}
public override void UpdateWorker(Worker Worker)
{
_WorkerCollection.ReplaceOne(b => b.Id == Worker.Id, Worker);
}
public override void DeleteWorker(int id)
{
_WorkerCollection.DeleteOne(Worker => Worker.Id == id);
}
public void UpdateSequence(Sequence sequence)
{
_sequenceCollection.ReplaceOne(seq => seq.Id == sequence.Id, sequence);
}
}
}

View File

@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\SYBDDatabaseImplement\SYBDDatabaseImplement.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,46 @@
using SYBDContracts.ViewModels;
using SYBDDatabaseImplement.Models;
namespace MongoDB.StorageModel
{
public abstract class StorageModel
{
// CDUD операции для каждой сущности
// Auto
public abstract void AddAuto(AutoViewModel auto);
public abstract List<Auto> GetAutos();
public abstract Auto GetAutoById(int id);
public abstract void UpdateAuto(Auto Auto);
public abstract void DeleteAuto(int id);
// Client
public abstract void AddClient(ClientViewModel client);
public abstract Client GetClientById(int id);
public abstract List<Client> GetClients();
public abstract void UpdateClient(Client client);
public abstract void DeleteClient(int id);
// Insurance
public abstract void AddInsurance(InsuranceViewModel Insurance);
public abstract Insurance GetInsuranceById(int id);
public abstract List<Insurance> GetInsurances();
public abstract void UpdateInsurance(Insurance Insurance);
public abstract void DeleteInsurance(int id);
// Order
public abstract void AddOrder(OrderViewModel Order);
public abstract Order GetOrderById(int id);
public abstract List<Order> GetOrders();
public abstract void UpdateOrder(Order Order);
public abstract void DeleteOrder(int id);
// Worker
public abstract void AddWorker(WorkerViewModel Worker);
public abstract Worker GetWorkerById(int id);
public abstract List<Worker> GetWorkeres();
public abstract void UpdateWorker(Worker Worker);
public abstract void DeleteWorker(int id);
}
}

View File

@ -28,198 +28,211 @@
/// </summary>
private void InitializeComponent()
{
this.buttonCreateOrder = new System.Windows.Forms.Button();
this.dataGridView = new System.Windows.Forms.DataGridView();
this.menuStrip1 = new System.Windows.Forms.MenuStrip();
this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.автомобилиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.клиентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.работникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.страховыеToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.buttonRef = new System.Windows.Forms.Button();
this.buttonDel = new System.Windows.Forms.Button();
this.buttonUpd = new System.Windows.Forms.Button();
this.buttonIssuedOrder = new System.Windows.Forms.Button();
this.buttonOrderReady = new System.Windows.Forms.Button();
this.buttonTakeOrderInWork = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.menuStrip1.SuspendLayout();
this.SuspendLayout();
//
// buttonCreateOrder
//
this.buttonCreateOrder.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.buttonCreateOrder.Location = new System.Drawing.Point(1081, 75);
this.buttonCreateOrder.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5);
this.buttonCreateOrder.Name = "buttonCreateOrder";
this.buttonCreateOrder.Size = new System.Drawing.Size(249, 45);
this.buttonCreateOrder.TabIndex = 7;
this.buttonCreateOrder.Text = "Создать заказ";
this.buttonCreateOrder.UseVisualStyleBackColor = true;
this.buttonCreateOrder.Click += new System.EventHandler(this.ButtonCreateOrder_Click);
//
// dataGridView
//
this.dataGridView.AllowUserToAddRows = false;
this.dataGridView.AllowUserToDeleteRows = false;
this.dataGridView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
this.buttonCreateOrder = new System.Windows.Forms.Button();
this.dataGridView = new System.Windows.Forms.DataGridView();
this.menuStrip1 = new System.Windows.Forms.MenuStrip();
this.справочникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.автомобилиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.клиентыToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.работникиToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.страховыеToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.buttonRef = new System.Windows.Forms.Button();
this.buttonDel = new System.Windows.Forms.Button();
this.buttonUpd = new System.Windows.Forms.Button();
this.buttonIssuedOrder = new System.Windows.Forms.Button();
this.buttonOrderReady = new System.Windows.Forms.Button();
this.buttonTakeOrderInWork = new System.Windows.Forms.Button();
this.button1 = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.menuStrip1.SuspendLayout();
this.SuspendLayout();
//
// buttonCreateOrder
//
this.buttonCreateOrder.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.buttonCreateOrder.Location = new System.Drawing.Point(1081, 75);
this.buttonCreateOrder.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5);
this.buttonCreateOrder.Name = "buttonCreateOrder";
this.buttonCreateOrder.Size = new System.Drawing.Size(249, 45);
this.buttonCreateOrder.TabIndex = 7;
this.buttonCreateOrder.Text = "Создать заказ";
this.buttonCreateOrder.UseVisualStyleBackColor = true;
this.buttonCreateOrder.Click += new System.EventHandler(this.ButtonCreateOrder_Click);
//
// dataGridView
//
this.dataGridView.AllowUserToAddRows = false;
this.dataGridView.AllowUserToDeleteRows = false;
this.dataGridView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight;
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView.Location = new System.Drawing.Point(2, 44);
this.dataGridView.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5);
this.dataGridView.MultiSelect = false;
this.dataGridView.Name = "dataGridView";
this.dataGridView.ReadOnly = true;
this.dataGridView.RowHeadersVisible = false;
this.dataGridView.RowHeadersWidth = 62;
this.dataGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
this.dataGridView.Size = new System.Drawing.Size(1055, 533);
this.dataGridView.TabIndex = 6;
//
// menuStrip1
//
this.menuStrip1.ImageScalingSize = new System.Drawing.Size(24, 24);
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.dataGridView.BackgroundColor = System.Drawing.SystemColors.ControlLightLight;
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
this.dataGridView.Location = new System.Drawing.Point(2, 44);
this.dataGridView.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5);
this.dataGridView.MultiSelect = false;
this.dataGridView.Name = "dataGridView";
this.dataGridView.ReadOnly = true;
this.dataGridView.RowHeadersVisible = false;
this.dataGridView.RowHeadersWidth = 62;
this.dataGridView.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
this.dataGridView.Size = new System.Drawing.Size(1055, 533);
this.dataGridView.TabIndex = 6;
//
// menuStrip1
//
this.menuStrip1.ImageScalingSize = new System.Drawing.Size(24, 24);
this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.справочникиToolStripMenuItem});
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
this.menuStrip1.Name = "menuStrip1";
this.menuStrip1.Size = new System.Drawing.Size(1377, 33);
this.menuStrip1.TabIndex = 12;
this.menuStrip1.Text = "menuStrip1";
//
// справочникиToolStripMenuItem
//
this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.menuStrip1.Location = new System.Drawing.Point(0, 0);
this.menuStrip1.Name = "menuStrip1";
this.menuStrip1.Size = new System.Drawing.Size(1377, 33);
this.menuStrip1.TabIndex = 12;
this.menuStrip1.Text = "menuStrip1";
//
// справочникиToolStripMenuItem
//
this.справочникиToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.автомобилиToolStripMenuItem,
this.клиентыToolStripMenuItem,
this.работникиToolStripMenuItem,
this.страховыеToolStripMenuItem});
this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem";
this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(139, 29);
this.справочникиToolStripMenuItem.Text = "Справочники";
//
// автомобилиToolStripMenuItem
//
this.автомобилиToolStripMenuItem.Name = "автомобилиToolStripMenuItem";
this.автомобилиToolStripMenuItem.Size = new System.Drawing.Size(217, 34);
this.автомобилиToolStripMenuItem.Text = "Автомобили";
this.автомобилиToolStripMenuItem.Click += new System.EventHandler(this.АвтомобилиToolStripMenuItem_Click);
//
// клиентыToolStripMenuItem
//
this.клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem";
this.клиентыToolStripMenuItem.Size = new System.Drawing.Size(217, 34);
this.клиентыToolStripMenuItem.Text = "Клиенты";
this.клиентыToolStripMenuItem.Click += new System.EventHandler(this.клиентыToolStripMenuItem_Click);
//
// работникиToolStripMenuItem
//
this.работникиToolStripMenuItem.Name = "работникиToolStripMenuItem";
this.работникиToolStripMenuItem.Size = new System.Drawing.Size(217, 34);
this.работникиToolStripMenuItem.Text = "Работники";
this.работникиToolStripMenuItem.Click += new System.EventHandler(this.РаботникиToolStripMenuItem_Click);
//
// страховыеToolStripMenuItem
//
this.страховыеToolStripMenuItem.Name = "страховыеToolStripMenuItem";
this.страховыеToolStripMenuItem.Size = new System.Drawing.Size(217, 34);
this.страховыеToolStripMenuItem.Text = "Страховые";
this.страховыеToolStripMenuItem.Click += new System.EventHandler(this.СтраховыеToolStripMenuItem_Click);
//
// buttonRef
//
this.buttonRef.Location = new System.Drawing.Point(1081, 516);
this.buttonRef.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6);
this.buttonRef.Name = "buttonRef";
this.buttonRef.Size = new System.Drawing.Size(249, 44);
this.buttonRef.TabIndex = 17;
this.buttonRef.Text = "Обновить";
this.buttonRef.UseVisualStyleBackColor = true;
this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click);
//
// buttonDel
//
this.buttonDel.Location = new System.Drawing.Point(1081, 437);
this.buttonDel.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6);
this.buttonDel.Name = "buttonDel";
this.buttonDel.Size = new System.Drawing.Size(249, 44);
this.buttonDel.TabIndex = 16;
this.buttonDel.Text = "Удалить";
this.buttonDel.UseVisualStyleBackColor = true;
this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click);
//
// buttonUpd
//
this.buttonUpd.Location = new System.Drawing.Point(1081, 370);
this.buttonUpd.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6);
this.buttonUpd.Name = "buttonUpd";
this.buttonUpd.Size = new System.Drawing.Size(249, 44);
this.buttonUpd.TabIndex = 15;
this.buttonUpd.Text = "Изменить";
this.buttonUpd.UseVisualStyleBackColor = true;
this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click);
//
// buttonIssuedOrder
//
this.buttonIssuedOrder.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.buttonIssuedOrder.Location = new System.Drawing.Point(1081, 283);
this.buttonIssuedOrder.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5);
this.buttonIssuedOrder.Name = "buttonIssuedOrder";
this.buttonIssuedOrder.Size = new System.Drawing.Size(249, 45);
this.buttonIssuedOrder.TabIndex = 20;
this.buttonIssuedOrder.Text = "Заказ выдан";
this.buttonIssuedOrder.UseVisualStyleBackColor = true;
this.buttonIssuedOrder.Click += new System.EventHandler(this.ButtonIssuedOrder_Click);
//
// buttonOrderReady
//
this.buttonOrderReady.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.buttonOrderReady.Location = new System.Drawing.Point(1081, 211);
this.buttonOrderReady.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5);
this.buttonOrderReady.Name = "buttonOrderReady";
this.buttonOrderReady.Size = new System.Drawing.Size(249, 45);
this.buttonOrderReady.TabIndex = 19;
this.buttonOrderReady.Text = "Заказ готов";
this.buttonOrderReady.UseVisualStyleBackColor = true;
this.buttonOrderReady.Click += new System.EventHandler(this.ButtonOrderReady_Click);
//
// buttonTakeOrderInWork
//
this.buttonTakeOrderInWork.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.buttonTakeOrderInWork.Location = new System.Drawing.Point(1081, 144);
this.buttonTakeOrderInWork.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5);
this.buttonTakeOrderInWork.Name = "buttonTakeOrderInWork";
this.buttonTakeOrderInWork.Size = new System.Drawing.Size(249, 45);
this.buttonTakeOrderInWork.TabIndex = 18;
this.buttonTakeOrderInWork.Text = "Отдать на выполнение";
this.buttonTakeOrderInWork.UseVisualStyleBackColor = true;
this.buttonTakeOrderInWork.Click += new System.EventHandler(this.ButtonTakeOrderInWork_Click);
//
// FormMain
//
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1377, 602);
this.Controls.Add(this.buttonIssuedOrder);
this.Controls.Add(this.buttonOrderReady);
this.Controls.Add(this.buttonTakeOrderInWork);
this.Controls.Add(this.buttonRef);
this.Controls.Add(this.buttonDel);
this.Controls.Add(this.buttonUpd);
this.Controls.Add(this.buttonCreateOrder);
this.Controls.Add(this.dataGridView);
this.Controls.Add(this.menuStrip1);
this.MainMenuStrip = this.menuStrip1;
this.Name = "FormMain";
this.Text = "Ремонт труб";
this.Load += new System.EventHandler(this.FormMain_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.menuStrip1.ResumeLayout(false);
this.menuStrip1.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
this.справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem";
this.справочникиToolStripMenuItem.Size = new System.Drawing.Size(139, 29);
this.справочникиToolStripMenuItem.Text = "Справочники";
//
// автомобилиToolStripMenuItem
//
this.автомобилиToolStripMenuItem.Name = "автомобилиToolStripMenuItem";
this.автомобилиToolStripMenuItem.Size = new System.Drawing.Size(217, 34);
this.автомобилиToolStripMenuItem.Text = "Автомобили";
this.автомобилиToolStripMenuItem.Click += new System.EventHandler(this.АвтомобилиToolStripMenuItem_Click);
//
// клиентыToolStripMenuItem
//
this.клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem";
this.клиентыToolStripMenuItem.Size = new System.Drawing.Size(217, 34);
this.клиентыToolStripMenuItem.Text = "Клиенты";
this.клиентыToolStripMenuItem.Click += new System.EventHandler(this.клиентыToolStripMenuItem_Click);
//
// работникиToolStripMenuItem
//
this.работникиToolStripMenuItem.Name = "работникиToolStripMenuItem";
this.работникиToolStripMenuItem.Size = new System.Drawing.Size(217, 34);
this.работникиToolStripMenuItem.Text = "Работники";
this.работникиToolStripMenuItem.Click += new System.EventHandler(this.РаботникиToolStripMenuItem_Click);
//
// страховыеToolStripMenuItem
//
this.страховыеToolStripMenuItem.Name = "страховыеToolStripMenuItem";
this.страховыеToolStripMenuItem.Size = new System.Drawing.Size(217, 34);
this.страховыеToolStripMenuItem.Text = "Страховые";
this.страховыеToolStripMenuItem.Click += new System.EventHandler(this.СтраховыеToolStripMenuItem_Click);
//
// buttonRef
//
this.buttonRef.Location = new System.Drawing.Point(1081, 493);
this.buttonRef.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6);
this.buttonRef.Name = "buttonRef";
this.buttonRef.Size = new System.Drawing.Size(249, 44);
this.buttonRef.TabIndex = 17;
this.buttonRef.Text = "Обновить";
this.buttonRef.UseVisualStyleBackColor = true;
this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click);
//
// buttonDel
//
this.buttonDel.Location = new System.Drawing.Point(1081, 437);
this.buttonDel.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6);
this.buttonDel.Name = "buttonDel";
this.buttonDel.Size = new System.Drawing.Size(249, 44);
this.buttonDel.TabIndex = 16;
this.buttonDel.Text = "Удалить";
this.buttonDel.UseVisualStyleBackColor = true;
this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click);
//
// buttonUpd
//
this.buttonUpd.Location = new System.Drawing.Point(1081, 370);
this.buttonUpd.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6);
this.buttonUpd.Name = "buttonUpd";
this.buttonUpd.Size = new System.Drawing.Size(249, 44);
this.buttonUpd.TabIndex = 15;
this.buttonUpd.Text = "Изменить";
this.buttonUpd.UseVisualStyleBackColor = true;
this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click);
//
// buttonIssuedOrder
//
this.buttonIssuedOrder.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.buttonIssuedOrder.Location = new System.Drawing.Point(1081, 283);
this.buttonIssuedOrder.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5);
this.buttonIssuedOrder.Name = "buttonIssuedOrder";
this.buttonIssuedOrder.Size = new System.Drawing.Size(249, 45);
this.buttonIssuedOrder.TabIndex = 20;
this.buttonIssuedOrder.Text = "Заказ выдан";
this.buttonIssuedOrder.UseVisualStyleBackColor = true;
this.buttonIssuedOrder.Click += new System.EventHandler(this.ButtonIssuedOrder_Click);
//
// buttonOrderReady
//
this.buttonOrderReady.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.buttonOrderReady.Location = new System.Drawing.Point(1081, 211);
this.buttonOrderReady.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5);
this.buttonOrderReady.Name = "buttonOrderReady";
this.buttonOrderReady.Size = new System.Drawing.Size(249, 45);
this.buttonOrderReady.TabIndex = 19;
this.buttonOrderReady.Text = "Заказ готов";
this.buttonOrderReady.UseVisualStyleBackColor = true;
this.buttonOrderReady.Click += new System.EventHandler(this.ButtonOrderReady_Click);
//
// buttonTakeOrderInWork
//
this.buttonTakeOrderInWork.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.buttonTakeOrderInWork.Location = new System.Drawing.Point(1081, 144);
this.buttonTakeOrderInWork.Margin = new System.Windows.Forms.Padding(6, 5, 6, 5);
this.buttonTakeOrderInWork.Name = "buttonTakeOrderInWork";
this.buttonTakeOrderInWork.Size = new System.Drawing.Size(249, 45);
this.buttonTakeOrderInWork.TabIndex = 18;
this.buttonTakeOrderInWork.Text = "Отдать на выполнение";
this.buttonTakeOrderInWork.UseVisualStyleBackColor = true;
this.buttonTakeOrderInWork.Click += new System.EventHandler(this.ButtonTakeOrderInWork_Click);
//
// button1
//
this.button1.Location = new System.Drawing.Point(1081, 543);
this.button1.Margin = new System.Windows.Forms.Padding(5, 6, 5, 6);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(249, 44);
this.button1.TabIndex = 21;
this.button1.Text = "Сменить бд";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.buttonTransferDataFromPostgresToMongo_Click);
//
// FormMain
//
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1377, 602);
this.Controls.Add(this.button1);
this.Controls.Add(this.buttonIssuedOrder);
this.Controls.Add(this.buttonOrderReady);
this.Controls.Add(this.buttonTakeOrderInWork);
this.Controls.Add(this.buttonRef);
this.Controls.Add(this.buttonDel);
this.Controls.Add(this.buttonUpd);
this.Controls.Add(this.buttonCreateOrder);
this.Controls.Add(this.dataGridView);
this.Controls.Add(this.menuStrip1);
this.MainMenuStrip = this.menuStrip1;
this.Name = "FormMain";
this.Text = "Ремонт труб";
this.Load += new System.EventHandler(this.FormMain_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
this.menuStrip1.ResumeLayout(false);
this.menuStrip1.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
@ -238,5 +251,6 @@
private Button buttonIssuedOrder;
private Button buttonOrderReady;
private Button buttonTakeOrderInWork;
}
private Button button1;
}
}

View File

@ -1,6 +1,8 @@
using Microsoft.Extensions.Logging;
using SYBDContracts.BindingModels;
using SYBDContracts.BusinessLogicsContracts;
using SYBDContracts.StoragesContracts;
using SYBDDatabaseImplement;
namespace SYBDView
{
@ -9,13 +11,22 @@ namespace SYBDView
private readonly ILogger _logger;
private readonly IOrderLogic _orderLogic;
private readonly IAutoStorage _autoStorage;
private readonly IClientStorage _clientStorage;
private readonly IInsuranceStorage _insuranceStorage;
private readonly IOrderStorage _orderStorage;
private readonly IWorkerStorage _workerStorage;
public FormMain(ILogger<FormMain> logger, IOrderLogic orderLogic)
public FormMain(ILogger<FormMain> logger, IOrderLogic orderLogic, IAutoStorage autoStorage, IClientStorage clientStorage, IInsuranceStorage insuranceStorage, IOrderStorage orderStorage, IWorkerStorage workerStorage)
{
InitializeComponent();
_logger = logger;
_orderLogic = orderLogic;
_autoStorage = autoStorage;
_clientStorage = clientStorage;
_orderStorage = orderStorage;
_workerStorage = workerStorage;
_insuranceStorage = insuranceStorage;
}
private void FormMain_Load(object sender, EventArgs e)
@ -163,8 +174,57 @@ namespace SYBDView
}
}
}
private void buttonTransferDataFromPostgresToMongo_Click(object sender, EventArgs e)
{
ImplementationMongoDB implementationMongoDB = new();
private void ButtonDel_Click(object sender, EventArgs e)
// очищаем всё
foreach (var it in implementationMongoDB.GetClients())
implementationMongoDB.DeleteClient(it.Id);
foreach (var it in implementationMongoDB.GetInsurances())
implementationMongoDB.DeleteInsurance(it.Id);
foreach (var it in implementationMongoDB.GetAutos())
implementationMongoDB.DeleteAuto(it.Id);
foreach (var it in implementationMongoDB.GetOrders())
implementationMongoDB.DeleteOrder(it.Id);
foreach (var it in implementationMongoDB.GetWorkeres())
implementationMongoDB.DeleteWorker(it.Id);
using var context = new SYBDDatabase();
// скачиваем из постгреса
var listAutos = _autoStorage.GetFullList();
var listClients = _clientStorage.GetFullList();
var listInsurances = _insuranceStorage.GetFullList();
var listOrders = _orderStorage.GetFullList();
var listWorkers = _workerStorage.GetFullList();
// вливаем данные монго дб
foreach (var it in listAutos)
implementationMongoDB.AddAuto(it);
foreach (var it in listClients)
implementationMongoDB.AddClient(it);
foreach (var it in listInsurances)
implementationMongoDB.AddInsurance(it);
foreach (var it in listOrders)
implementationMongoDB.AddOrder(it);
foreach (var it in listWorkers)
implementationMongoDB.AddWorker(it);
// забираем информацию о последовательностях
var listSequence = context.GetSequences();
foreach (var it in listSequence)
if (it.Id == "auto" ||
it.Id == "client" ||
it.Id == "insurance" ||
it.Id == "order" ||
it.Id == "worker"
)
implementationMongoDB.UpdateSequence(it);
else
throw new Exception("неправильный id последовательности");
}
private void ButtonDel_Click(object sender, EventArgs e)
{
if (dataGridView.SelectedRows.Count == 1)
{

View File

@ -1,9 +1,11 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using MongoDB.StorageModel;
using NLog.Extensions.Logging;
using SYBDBusinessLogic.BusinessLogics;
using SYBDContracts.BusinessLogicsContracts;
using SYBDContracts.StoragesContracts;
using SYBDDatabaseImplement;
using SYBDDatabaseImplement.Implements;
namespace SYBDView
@ -13,10 +15,46 @@ namespace SYBDView
private static ServiceProvider? _serviceProvider;
public static ServiceProvider? ServiceProvider => _serviceProvider;
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
/// <summary>
/// The main entry point for the application.
/// </summary>
///
private static bool isPostgreSQL = true;
private static void ConfigureServices(ServiceCollection services)
{
services.AddLogging(option =>
{
option.SetMinimumLevel(LogLevel.Information);
option.AddNLog("nlog.config");
});
if (!isPostgreSQL)
{
services.AddTransient<StorageModel, ImplementationMongoDB>();
}
services.AddTransient<IAutoStorage, AutoStorage>();
services.AddTransient<IWorkerStorage, WorkerStorage>();
services.AddTransient<IOrderStorage, OrderStorage>();
services.AddTransient<IInsuranceStorage, InsuranceStorage>();
services.AddTransient<IClientStorage, ClientStorage>();
services.AddTransient<IAutoLogic, AutoLogic>();
services.AddTransient<IOrderLogic, OrderLogic>();
services.AddTransient<IWorkerLogic, WorkerLogic>();
services.AddTransient<IInsuranceLogic, InsuranceLogic>();
services.AddTransient<IClientLogic, ClientLogic>();
services.AddTransient<FormMain>();
services.AddTransient<FormAuto>();
services.AddTransient<FormAutos>();
services.AddTransient<FormCreateOrder>();
services.AddTransient<FormWorker>();
services.AddTransient<FormWorkers>();
services.AddTransient<FormInsurance>();
services.AddTransient<FormInsurances>();
services.AddTransient<FormClients>();
services.AddTransient<FormClient>();
}
[STAThread]
static void Main()
{
// To customize application configuration such as set high DPI settings or default font,
@ -28,35 +66,21 @@ namespace SYBDView
Application.Run(_serviceProvider.GetRequiredService<FormMain>());
}
private static void ConfigureServices(ServiceCollection services)
{
services.AddLogging(option =>
{
option.SetMinimumLevel(LogLevel.Information);
option.AddNLog("nlog.config");
});
services.AddTransient<IAutoStorage, AutoStorage>();
services.AddTransient<IWorkerStorage, WorkerStorage>();
services.AddTransient<IOrderStorage, OrderStorage>();
services.AddTransient<IInsuranceStorage, InsuranceStorage>();
services.AddTransient<IClientStorage, ClientStorage>();
services.AddTransient<IAutoLogic, AutoLogic>();
services.AddTransient<IOrderLogic, OrderLogic>();
services.AddTransient<IWorkerLogic, WorkerLogic>();
services.AddTransient<IInsuranceLogic, InsuranceLogic>();
services.AddTransient<IClientLogic, ClientLogic>();
services.AddTransient<FormMain>();
services.AddTransient<FormAuto>();
services.AddTransient<FormAutos>();
services.AddTransient<FormCreateOrder>();
services.AddTransient<FormWorker>();
services.AddTransient<FormWorkers>();
services.AddTransient<FormInsurance>();
services.AddTransient<FormInsurances>();
services.AddTransient<FormClients>();
services.AddTransient<FormClient>();
}
}
public static void ChangeDB()
{
isPostgreSQL = !isPostgreSQL;
var services = new ServiceCollection();
ConfigureServices(services);
_serviceProvider = services.BuildServiceProvider();
}
public static void ChangeDB(bool newIsPostrgeSQL)
{
if (newIsPostrgeSQL == isPostgreSQL)
return;
isPostgreSQL = newIsPostrgeSQL;
var services = new ServiceCollection();
ConfigureServices(services);
_serviceProvider = services.BuildServiceProvider();
}
}
}

View File

@ -19,6 +19,7 @@
<ItemGroup>
<ProjectReference Include="..\SYBDBusinessLogic\SYBDBusinessLogic.csproj" />
<ProjectReference Include="..\SYBDDatabaseImplement\SYBDDatabaseImplement.csproj" />
<ProjectReference Include="..\SYBDMongoDB\SYBDMongoDB.csproj" />
</ItemGroup>
</Project>

View File

@ -4,7 +4,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
autoReload="true" internalLogLevel="Info">
<targets>
<target xsi:type="File" name="tofile" fileName="carlog-
<target xsi:type="File" name="tofile" fileName="Autolog-
${shortdate}.log" />
</targets>
<rules>