Compare commits

..

No commits in common. "1758e6f5cedff57c057c2418bd73fb6c3cbf8c81" and "3e837d8492511ca514989f99adc9bc627c980a03" have entirely different histories.

7 changed files with 132 additions and 441 deletions

View File

@ -20,154 +20,115 @@
base.Dispose(disposing);
}
#region Windows Form Designer generated code
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
menuStrip1 = new MenuStrip();
tablesToolStripMenuItem = new ToolStripMenuItem();
carModelToolStripMenuItem = new ToolStripMenuItem();
carToolStripMenuItem = new ToolStripMenuItem();
branchToolStripMenuItem = new ToolStripMenuItem();
clientToolStripMenuItem = new ToolStripMenuItem();
rentalToolStripMenuItem = new ToolStripMenuItem();
buttonTest = new Button();
textBoxTest = new TextBox();
trackBarDB = new TrackBar();
labelPostrges = new Label();
labelMongoDB = new Label();
menuStrip1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)trackBarDB).BeginInit();
SuspendLayout();
//
// menuStrip1
//
menuStrip1.Items.AddRange(new ToolStripItem[] { tablesToolStripMenuItem });
menuStrip1.Location = new Point(0, 0);
menuStrip1.Name = "menuStrip1";
menuStrip1.Size = new Size(435, 24);
menuStrip1.TabIndex = 0;
menuStrip1.Text = "menuStrip1";
//
// tablesToolStripMenuItem
//
tablesToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { carModelToolStripMenuItem, carToolStripMenuItem, branchToolStripMenuItem, clientToolStripMenuItem, rentalToolStripMenuItem });
tablesToolStripMenuItem.Name = "tablesToolStripMenuItem";
tablesToolStripMenuItem.Size = new Size(50, 20);
tablesToolStripMenuItem.Text = "tables";
//
// carModelToolStripMenuItem
//
carModelToolStripMenuItem.Name = "carModelToolStripMenuItem";
carModelToolStripMenuItem.Size = new Size(127, 22);
carModelToolStripMenuItem.Text = "car model";
carModelToolStripMenuItem.Click += carModelToolStripMenuItem_Click;
//
// carToolStripMenuItem
//
carToolStripMenuItem.Name = "carToolStripMenuItem";
carToolStripMenuItem.Size = new Size(127, 22);
carToolStripMenuItem.Text = "car";
carToolStripMenuItem.Click += carToolStripMenuItem_Click;
//
// branchToolStripMenuItem
//
branchToolStripMenuItem.Name = "branchToolStripMenuItem";
branchToolStripMenuItem.Size = new Size(127, 22);
branchToolStripMenuItem.Text = "branch";
branchToolStripMenuItem.Click += branchToolStripMenuItem_Click;
//
// clientToolStripMenuItem
//
clientToolStripMenuItem.Name = "clientToolStripMenuItem";
clientToolStripMenuItem.Size = new Size(127, 22);
clientToolStripMenuItem.Text = "client";
clientToolStripMenuItem.Click += clientToolStripMenuItem_Click;
//
// rentalToolStripMenuItem
//
rentalToolStripMenuItem.Name = "rentalToolStripMenuItem";
rentalToolStripMenuItem.Size = new Size(127, 22);
rentalToolStripMenuItem.Text = "rental";
rentalToolStripMenuItem.Click += rentalToolStripMenuItem_Click;
//
// buttonTest
//
buttonTest.Location = new Point(75, 229);
buttonTest.Name = "buttonTest";
buttonTest.Size = new Size(75, 23);
buttonTest.TabIndex = 1;
buttonTest.Text = "buttonTest";
buttonTest.UseVisualStyleBackColor = true;
buttonTest.Click += buttonTest_Click;
//
// textBoxTest
//
textBoxTest.Location = new Point(172, 230);
textBoxTest.Multiline = true;
textBoxTest.Name = "textBoxTest";
textBoxTest.Size = new Size(251, 75);
textBoxTest.TabIndex = 2;
//
// trackBarDB
//
trackBarDB.LargeChange = 1;
trackBarDB.Location = new Point(12, 34);
trackBarDB.Maximum = 100;
trackBarDB.Name = "trackBarDB";
trackBarDB.Orientation = Orientation.Vertical;
trackBarDB.Size = new Size(45, 64);
trackBarDB.TabIndex = 3;
trackBarDB.MouseUp += trackBarDB_MouseUp;
//
// labelPostrges
//
labelPostrges.AutoSize = true;
labelPostrges.Font = new Font("Segoe UI", 20F, FontStyle.Regular, GraphicsUnit.Point);
labelPostrges.Location = new Point(33, 64);
labelPostrges.Name = "labelPostrges";
labelPostrges.Size = new Size(117, 37);
labelPostrges.TabIndex = 4;
labelPostrges.Text = "Postrges";
//
// labelMongoDB
//
labelMongoDB.AutoSize = true;
labelMongoDB.Font = new Font("Segoe UI", 20F, FontStyle.Regular, GraphicsUnit.Point);
labelMongoDB.Location = new Point(33, 27);
labelMongoDB.Name = "labelMongoDB";
labelMongoDB.Size = new Size(138, 37);
labelMongoDB.TabIndex = 5;
labelMongoDB.Text = "MongoDB";
//
// FormMain
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(435, 317);
Controls.Add(labelMongoDB);
Controls.Add(labelPostrges);
Controls.Add(trackBarDB);
Controls.Add(textBoxTest);
Controls.Add(buttonTest);
Controls.Add(menuStrip1);
MainMenuStrip = menuStrip1;
Name = "FormMain";
Text = "FormMain";
menuStrip1.ResumeLayout(false);
menuStrip1.PerformLayout();
((System.ComponentModel.ISupportInitialize)trackBarDB).EndInit();
ResumeLayout(false);
PerformLayout();
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
menuStrip1 = new MenuStrip();
tablesToolStripMenuItem = new ToolStripMenuItem();
carModelToolStripMenuItem = new ToolStripMenuItem();
carToolStripMenuItem = new ToolStripMenuItem();
branchToolStripMenuItem = new ToolStripMenuItem();
clientToolStripMenuItem = new ToolStripMenuItem();
rentalToolStripMenuItem = new ToolStripMenuItem();
buttonTest = new Button();
textBoxTest = new TextBox();
menuStrip1.SuspendLayout();
SuspendLayout();
//
// menuStrip1
//
menuStrip1.Items.AddRange(new ToolStripItem[] { tablesToolStripMenuItem });
menuStrip1.Location = new Point(0, 0);
menuStrip1.Name = "menuStrip1";
menuStrip1.Size = new Size(435, 24);
menuStrip1.TabIndex = 0;
menuStrip1.Text = "menuStrip1";
//
// tablesToolStripMenuItem
//
tablesToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { carModelToolStripMenuItem, carToolStripMenuItem, branchToolStripMenuItem, clientToolStripMenuItem, rentalToolStripMenuItem });
tablesToolStripMenuItem.Name = "tablesToolStripMenuItem";
tablesToolStripMenuItem.Size = new Size(50, 20);
tablesToolStripMenuItem.Text = "tables";
//
// carModelToolStripMenuItem
//
carModelToolStripMenuItem.Name = "carModelToolStripMenuItem";
carModelToolStripMenuItem.Size = new Size(127, 22);
carModelToolStripMenuItem.Text = "car model";
carModelToolStripMenuItem.Click += carModelToolStripMenuItem_Click;
//
// carToolStripMenuItem
//
carToolStripMenuItem.Name = "carToolStripMenuItem";
carToolStripMenuItem.Size = new Size(127, 22);
carToolStripMenuItem.Text = "car";
carToolStripMenuItem.Click += carToolStripMenuItem_Click;
//
// branchToolStripMenuItem
//
branchToolStripMenuItem.Name = "branchToolStripMenuItem";
branchToolStripMenuItem.Size = new Size(127, 22);
branchToolStripMenuItem.Text = "branch";
branchToolStripMenuItem.Click += branchToolStripMenuItem_Click;
//
// clientToolStripMenuItem
//
clientToolStripMenuItem.Name = "clientToolStripMenuItem";
clientToolStripMenuItem.Size = new Size(127, 22);
clientToolStripMenuItem.Text = "client";
clientToolStripMenuItem.Click += clientToolStripMenuItem_Click;
//
// rentalToolStripMenuItem
//
rentalToolStripMenuItem.Name = "rentalToolStripMenuItem";
rentalToolStripMenuItem.Size = new Size(127, 22);
rentalToolStripMenuItem.Text = "rental";
rentalToolStripMenuItem.Click += rentalToolStripMenuItem_Click;
//
// buttonTest
//
buttonTest.Location = new Point(24, 50);
buttonTest.Name = "buttonTest";
buttonTest.Size = new Size(75, 23);
buttonTest.TabIndex = 1;
buttonTest.Text = "buttonTest";
buttonTest.UseVisualStyleBackColor = true;
buttonTest.Click += buttonTest_Click;
//
// textBoxTest
//
textBoxTest.Location = new Point(121, 51);
textBoxTest.Multiline = true;
textBoxTest.Name = "textBoxTest";
textBoxTest.Size = new Size(251, 75);
textBoxTest.TabIndex = 2;
//
// FormMain
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(435, 167);
Controls.Add(textBoxTest);
Controls.Add(buttonTest);
Controls.Add(menuStrip1);
MainMenuStrip = menuStrip1;
Name = "FormMain";
Text = "FormMain";
menuStrip1.ResumeLayout(false);
menuStrip1.PerformLayout();
ResumeLayout(false);
PerformLayout();
}
#endregion
#endregion
private MenuStrip menuStrip1;
private MenuStrip menuStrip1;
private ToolStripMenuItem tablesToolStripMenuItem;
private ToolStripMenuItem carModelToolStripMenuItem;
private ToolStripMenuItem carToolStripMenuItem;
@ -176,8 +137,5 @@
private ToolStripMenuItem rentalToolStripMenuItem;
private Button buttonTest;
private TextBox textBoxTest;
private TrackBar trackBarDB;
private Label labelPostrges;
private Label labelMongoDB;
}
}
}

View File

@ -82,21 +82,7 @@ namespace Forms
}
}
private void trackBarDB_MouseUp(object sender, MouseEventArgs e)
{
if (trackBarDB.Value > 50)
{
trackBarDB.Value = 100;
Program.ChangeDB(false);
}
else
{
trackBarDB.Value = 0;
Program.ChangeDB(true);
}
}
/*
/*
private Abstractions bd = new Implementation();
private void button1_Click(object sender, EventArgs e)
{

View File

@ -7,31 +7,10 @@ namespace Forms
{
private static ServiceProvider? _serviceProvider;
public static ServiceProvider? ServiceProvider => _serviceProvider;
private static bool isPostgreSQL = true;
private static void ConfigureServices(ServiceCollection services)
{
if (isPostgreSQL)
{
services.AddTransient<Abstractions, ImplementationPostgres>();
}
else
{
services.AddTransient<Abstractions, ImplementationMongoDB>();
}
services.AddTransient<FormMain>();
services.AddTransient<FormBranch>();
services.AddTransient<FormCar>();
services.AddTransient<FormCarModel>();
services.AddTransient<FormClient>();
services.AddTransient<FormRental>();
}
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
// To customize application configuration such as set high DPI settings or default font,
@ -42,22 +21,15 @@ namespace Forms
_serviceProvider = services.BuildServiceProvider();
Application.Run(_serviceProvider.GetRequiredService<FormMain>());
}
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();
}
}
private static void ConfigureServices(ServiceCollection services)
{
services.AddTransient<Abstractions, Implementation>();
services.AddTransient<FormMain>();
services.AddTransient<FormBranch>();
services.AddTransient<FormCar>();
services.AddTransient<FormCarModel>();
services.AddTransient<FormClient>();
services.AddTransient<FormRental>();
}
}
}

View File

@ -2,7 +2,7 @@
namespace database
{
public class ImplementationPostgres : Abstractions
public class Implementation : Abstractions
{
private NpgsqlConnection GetConnection()
{

View File

@ -1,214 +0,0 @@
using MongoDB.Driver;
namespace database
{
public class ImplementationMongoDB : Abstractions
{
private IMongoDatabase _database;
private IMongoCollection<Car> _carCollection;
private IMongoCollection<Client> _clientCollection;
private IMongoCollection<Rental> _rentalCollection;
private IMongoCollection<CarModel> _carModelCollection;
private IMongoCollection<Branch> _branchCollection;
private IMongoCollection<Status> _statusCollection;
private IMongoCollection<BodyType> _bodyTypeCollection;
public ImplementationMongoDB()
{
var client = new MongoClient("mongodb://localhost:27017");
_database = client.GetDatabase("car_rent");
_carCollection = _database.GetCollection<Car>("car");
_clientCollection = _database.GetCollection<Client>("client");
_rentalCollection = _database.GetCollection<Rental>("rental");
_carModelCollection = _database.GetCollection<CarModel>("car_model");
_branchCollection = _database.GetCollection<Branch>("branch");
_statusCollection = _database.GetCollection<Status>("status");
_bodyTypeCollection = _database.GetCollection<BodyType>("body_type");
}
// CDUD îïåðàöèè äëÿ êàæäîé ñóùíîñòè
// Car
public override void AddCar(Car car)
{
_carCollection.InsertOne(car);
}
public override List<Car> GetCars()
{
return _carCollection.Find(_ => true).ToList();
}
public override Car GetCarById(int id)
{
return _carCollection.Find(car => car.Id == id).FirstOrDefault();
}
public override void UpdateCar(Car car)
{
_carCollection.ReplaceOne(c => c.Id == car.Id, car);
}
public override void DeleteCar(int id)
{
_carCollection.DeleteOne(car => car.Id == id);
}
// Client
public override void AddClient(Client client)
{
_clientCollection.InsertOne(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);
}
// Rental
public override void AddRental(Rental rental)
{
_rentalCollection.InsertOne(rental);
}
public override List<Rental> GetRentals()
{
return _rentalCollection.Find(_ => true).ToList();
}
public override Rental GetRentalById(int id)
{
return _rentalCollection.Find(rental => rental.Id == id).FirstOrDefault();
}
public override void UpdateRental(Rental rental)
{
_rentalCollection.ReplaceOne(r => r.Id == rental.Id, rental);
}
public override void DeleteRental(int id)
{
_rentalCollection.DeleteOne(rental => rental.Id == id);
}
// CarModel
public override void AddCarModel(CarModel carModel)
{
_carModelCollection.InsertOne(carModel);
}
public override List<CarModel> GetCarModels()
{
return _carModelCollection.Find(_ => true).ToList();
}
public override CarModel GetCarModelById(int id)
{
return _carModelCollection.Find(model => model.Id == id).FirstOrDefault();
}
public override void UpdateCarModel(CarModel carModel)
{
_carModelCollection.ReplaceOne(m => m.Id == carModel.Id, carModel);
}
public override void DeleteCarModel(int id)
{
_carModelCollection.DeleteOne(model => model.Id == id);
}
// Branch
public override void AddBranch(Branch branch)
{
_branchCollection.InsertOne(branch);
}
public override List<Branch> GetBranches()
{
return _branchCollection.Find(_ => true).ToList();
}
public override Branch GetBranchById(int id)
{
return _branchCollection.Find(branch => branch.Id == id).FirstOrDefault();
}
public override void UpdateBranch(Branch branch)
{
_branchCollection.ReplaceOne(b => b.Id == branch.Id, branch);
}
public override void DeleteBranch(int id)
{
_branchCollection.DeleteOne(branch => branch.Id == id);
}
// Status
public override void AddStatus(Status status)
{
_statusCollection.InsertOne(status);
}
public override List<Status> GetStatuses()
{
return _statusCollection.Find(_ => true).ToList();
}
public override Status GetStatusById(int id)
{
return _statusCollection.Find(status => status.Id == id).FirstOrDefault();
}
public override void UpdateStatus(Status status)
{
_statusCollection.ReplaceOne(s => s.Id == status.Id, status);
}
public override void DeleteStatus(int id)
{
_statusCollection.DeleteOne(status => status.Id == id);
}
// BodyType
public override void AddBodyType(BodyType bodyType)
{
_bodyTypeCollection.InsertOne(bodyType);
}
public override List<BodyType> GetBodyTypes()
{
return _bodyTypeCollection.Find(_ => true).ToList();
}
public override BodyType GetBodyTypeById(int id)
{
return _bodyTypeCollection.Find(bodyType => bodyType.Id == id).FirstOrDefault();
}
public override void UpdateBodyType(BodyType bodyType)
{
_bodyTypeCollection.ReplaceOne(b => b.Id == bodyType.Id, bodyType);
}
public override void DeleteBodyType(int id)
{
_bodyTypeCollection.DeleteOne(bodyType => bodyType.Id == id);
}
}
}

View File

@ -7,7 +7,6 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MongoDB.Driver" Version="2.25.0" />
<PackageReference Include="Npgsql" Version="8.0.2" />
</ItemGroup>

View File

@ -1,14 +1,10 @@
using MongoDB.Bson.Serialization.Attributes;
using MongoDB.Bson;
namespace database
namespace database
{
// Определение моделей данных
public class Car
{
[BsonRepresentation(BsonType.Int32)]
public int Id { get; set; }
public int Id { get; set; }
public int ModelId { get; set; }
public int BranchId { get; set; }
public int Year { get; set; }
@ -18,8 +14,7 @@ namespace database
public class Client
{
[BsonRepresentation(BsonType.Int32)]
public int Id { get; set; }
public int Id { get; set; }
public string Name { get; set; }
public string Surname { get; set; }
public string Address { get; set; }
@ -29,8 +24,7 @@ namespace database
public class Rental
{
[BsonRepresentation(BsonType.Int32)]
public int Id { get; set; }
public int Id { get; set; }
public int CarId { get; set; }
public int ClientId { get; set; }
public DateTime StartDate { get; set; }
@ -40,8 +34,7 @@ namespace database
public class CarModel
{
[BsonRepresentation(BsonType.Int32)]
public int Id { get; set; }
public int Id { get; set; }
public string Brand { get; set; }
public string Model { get; set; }
public int Year { get; set; }
@ -51,8 +44,7 @@ namespace database
public class Branch
{
[BsonRepresentation(BsonType.Int32)]
public int Id { get; set; }
public int Id { get; set; }
public string Name { get; set; }
public string Address { get; set; }
public string Phone { get; set; }
@ -61,15 +53,13 @@ namespace database
public class Status
{
[BsonRepresentation(BsonType.Int32)]
public int Id { get; set; }
public int Id { get; set; }
public string Title { get; set; }
}
public class BodyType
{
[BsonRepresentation(BsonType.Int32)]
public int Id { get; set; }
public int Id { get; set; }
public string Title { get; set; }
}