добавлено переключение между разными субд

This commit is contained in:
Timourka 2024-05-07 22:49:14 +04:00
parent a6f2dc683f
commit 1758e6f5ce
3 changed files with 207 additions and 123 deletions

View File

@ -20,115 +20,154 @@
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();
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();
}
/// <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();
}
#endregion
#endregion
private MenuStrip menuStrip1;
private MenuStrip menuStrip1;
private ToolStripMenuItem tablesToolStripMenuItem;
private ToolStripMenuItem carModelToolStripMenuItem;
private ToolStripMenuItem carToolStripMenuItem;
@ -137,5 +176,8 @@
private ToolStripMenuItem rentalToolStripMenuItem;
private Button buttonTest;
private TextBox textBoxTest;
}
private TrackBar trackBarDB;
private Label labelPostrges;
private Label labelMongoDB;
}
}

View File

@ -82,7 +82,21 @@ 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,10 +7,31 @@ namespace Forms
{
private static ServiceProvider? _serviceProvider;
public static ServiceProvider? ServiceProvider => _serviceProvider;
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
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]
static void Main()
{
// To customize application configuration such as set high DPI settings or default font,
@ -21,15 +42,22 @@ namespace Forms
_serviceProvider = services.BuildServiceProvider();
Application.Run(_serviceProvider.GetRequiredService<FormMain>());
}
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>();
}
}
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();
}
}
}