пофиксила проблемы и добавила кнопку очищения базы данных
This commit is contained in:
parent
6fc117f2dd
commit
a882e62323
@ -113,7 +113,7 @@ namespace BeautySalon
|
||||
{
|
||||
chequeStorage.Add(new Cheque
|
||||
{
|
||||
MasterId = 33,
|
||||
MasterId = 27,
|
||||
ServiceId = 40,
|
||||
ClientId = i % 2 + 2,
|
||||
Price = i * 10,
|
||||
|
@ -40,8 +40,7 @@ namespace BeautySalon
|
||||
long nano = sw.ElapsedTicks * 1000000000L / Stopwatch.Frequency;
|
||||
long sec = sw.ElapsedMilliseconds;
|
||||
FormTimeOperation form = new FormTimeOperation("Update", nano, sec);
|
||||
form.ShowDialog();
|
||||
if (form.ShowDialog() == DialogResult.OK) { DialogResult = DialogResult.OK; Close(); }
|
||||
form.Show();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -57,8 +56,7 @@ namespace BeautySalon
|
||||
long nano = sw.ElapsedTicks * 1000000000L / Stopwatch.Frequency;
|
||||
long sec = sw.ElapsedMilliseconds;
|
||||
FormTimeOperation form = new FormTimeOperation("Insert", nano, sec);
|
||||
form.ShowDialog();
|
||||
if (form.ShowDialog() == DialogResult.OK) { DialogResult = DialogResult.OK; Close(); }
|
||||
form.Show();
|
||||
}
|
||||
DialogResult = DialogResult.OK;
|
||||
Close();
|
||||
|
@ -88,8 +88,7 @@ namespace BeautySalon
|
||||
long sec = sw.ElapsedMilliseconds;
|
||||
long nano = sw.ElapsedTicks * 1000000000L / Stopwatch.Frequency;
|
||||
FormTimeOperation form = new FormTimeOperation("Delete", nano, sec);
|
||||
form.ShowDialog();
|
||||
if (form.ShowDialog() == DialogResult.OK) { DialogResult = DialogResult.OK; Close(); }
|
||||
form.Show();
|
||||
|
||||
LoadData();
|
||||
}
|
||||
@ -117,7 +116,6 @@ namespace BeautySalon
|
||||
long nano = sw.ElapsedTicks * 1000000000L / Stopwatch.Frequency;
|
||||
FormTimeOperation form = new FormTimeOperation("Generate and loadData", nano, sec);
|
||||
form.ShowDialog();
|
||||
if (form.ShowDialog() == DialogResult.OK) { DialogResult = DialogResult.OK; Close(); }
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
29
BeautySalon/BeautySalon/FormMain.Designer.cs
generated
29
BeautySalon/BeautySalon/FormMain.Designer.cs
generated
@ -35,13 +35,16 @@
|
||||
добавитьToolStripMenuItem1 = new ToolStripMenuItem();
|
||||
создатьПриемToolStripMenuItem = new ToolStripMenuItem();
|
||||
посмотретьЧекиToolStripMenuItem = new ToolStripMenuItem();
|
||||
очиститьБдToolStripMenuItem = new ToolStripMenuItem();
|
||||
toolStripMenuItem1 = new ToolStripMenuItem();
|
||||
toolStripMenuItem2 = new ToolStripMenuItem();
|
||||
menuStrip1.SuspendLayout();
|
||||
SuspendLayout();
|
||||
//
|
||||
// menuStrip1
|
||||
//
|
||||
menuStrip1.ImageScalingSize = new Size(20, 20);
|
||||
menuStrip1.Items.AddRange(new ToolStripItem[] { добавитьСпециализациюToolStripMenuItem, добавитьМастераToolStripMenuItem, добавитьToolStripMenuItem, добавитьToolStripMenuItem1, создатьПриемToolStripMenuItem, посмотретьЧекиToolStripMenuItem });
|
||||
menuStrip1.Items.AddRange(new ToolStripItem[] { добавитьСпециализациюToolStripMenuItem, добавитьМастераToolStripMenuItem, добавитьToolStripMenuItem, добавитьToolStripMenuItem1, создатьПриемToolStripMenuItem, посмотретьЧекиToolStripMenuItem, очиститьБдToolStripMenuItem, toolStripMenuItem1, toolStripMenuItem2 });
|
||||
menuStrip1.Location = new Point(0, 0);
|
||||
menuStrip1.Name = "menuStrip1";
|
||||
menuStrip1.Size = new Size(929, 28);
|
||||
@ -84,10 +87,27 @@
|
||||
// посмотретьЧекиToolStripMenuItem
|
||||
//
|
||||
посмотретьЧекиToolStripMenuItem.Name = "посмотретьЧекиToolStripMenuItem";
|
||||
посмотретьЧекиToolStripMenuItem.Size = new Size(172, 24);
|
||||
посмотретьЧекиToolStripMenuItem.Text = "Запись на процедуру";
|
||||
посмотретьЧекиToolStripMenuItem.Size = new Size(207, 24);
|
||||
посмотретьЧекиToolStripMenuItem.Text = "Записаться на ноготочЬки";
|
||||
посмотретьЧекиToolStripMenuItem.Click += посмотретьЧекиToolStripMenuItem_Click;
|
||||
//
|
||||
// очиститьБдToolStripMenuItem
|
||||
//
|
||||
очиститьБдToolStripMenuItem.Name = "очиститьБдToolStripMenuItem";
|
||||
очиститьБдToolStripMenuItem.Size = new Size(108, 24);
|
||||
очиститьБдToolStripMenuItem.Text = "Очистить бд";
|
||||
очиститьБдToolStripMenuItem.Click += очиститьБдToolStripMenuItem_Click;
|
||||
//
|
||||
// toolStripMenuItem1
|
||||
//
|
||||
toolStripMenuItem1.Name = "toolStripMenuItem1";
|
||||
toolStripMenuItem1.Size = new Size(14, 24);
|
||||
//
|
||||
// toolStripMenuItem2
|
||||
//
|
||||
toolStripMenuItem2.Name = "toolStripMenuItem2";
|
||||
toolStripMenuItem2.Size = new Size(14, 24);
|
||||
//
|
||||
// FormMain
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
@ -112,5 +132,8 @@
|
||||
private ToolStripMenuItem добавитьToolStripMenuItem1;
|
||||
private ToolStripMenuItem создатьПриемToolStripMenuItem;
|
||||
private ToolStripMenuItem посмотретьЧекиToolStripMenuItem;
|
||||
private ToolStripMenuItem очиститьБдToolStripMenuItem;
|
||||
private ToolStripMenuItem toolStripMenuItem1;
|
||||
private ToolStripMenuItem toolStripMenuItem2;
|
||||
}
|
||||
}
|
@ -1,5 +1,7 @@
|
||||
using BeautySalonDBModels;
|
||||
using BeautySalonDatabase.Implements;
|
||||
using BeautySalonDBModels;
|
||||
using BeautySalonDBModels.Implements;
|
||||
using BeautySalonDBModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
@ -14,7 +16,6 @@ namespace BeautySalon
|
||||
{
|
||||
public partial class FormMain : Form
|
||||
{
|
||||
|
||||
public FormMain()
|
||||
{
|
||||
InitializeComponent();
|
||||
@ -75,5 +76,11 @@ namespace BeautySalon
|
||||
form.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
private void очиститьБдToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
ServiceDatabase sdb = new ServiceDatabase();
|
||||
sdb.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -101,7 +101,7 @@ namespace BeautySalon
|
||||
masterDb.Add(new Master
|
||||
{
|
||||
FIO = i.ToString(),
|
||||
SpecialisationId = 15,
|
||||
SpecialisationId = 13,
|
||||
});
|
||||
}
|
||||
sw.Stop();
|
||||
|
@ -51,6 +51,7 @@ namespace BeautySalon
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormService));
|
||||
if (service is FormService form)
|
||||
{
|
||||
form.FormBorderStyle = FormBorderStyle.FixedSingle;
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
LoadData();
|
||||
@ -101,7 +102,7 @@ namespace BeautySalon
|
||||
serviceStorage.Add(new Service
|
||||
{
|
||||
ServiceName = i.ToString(),
|
||||
SpecialisationId = 14,
|
||||
SpecialisationId = 13,
|
||||
Price = i * 10
|
||||
}) ;
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
using BeautySalonDatabase.Implements;
|
||||
using BeautySalonDBModels;
|
||||
using BeautySalonDBModels.Implements;
|
||||
using BeautySalonDBModels.Models;
|
||||
@ -44,7 +45,7 @@ namespace BeautySalon
|
||||
services.AddSingleton<AbstractWorkWithStorage<Client>, ClientDatabase>();
|
||||
services.AddSingleton<AbstractWorkWithStorage<Service>, ServiceDatabase>();
|
||||
|
||||
|
||||
services.AddTransient<ClearDatabase>();
|
||||
|
||||
services.AddTransient<FormMain>();
|
||||
services.AddTransient<FormHello>();
|
||||
|
36
BeautySalon/BeautySalonDBModels/Implements/ClearDatabase.cs
Normal file
36
BeautySalon/BeautySalonDBModels/Implements/ClearDatabase.cs
Normal file
@ -0,0 +1,36 @@
|
||||
using Npgsql;
|
||||
|
||||
namespace BeautySalonDatabase.Implements
|
||||
{
|
||||
public class ClearDatabase
|
||||
{
|
||||
public void Clear()
|
||||
{
|
||||
using var conn = GetConnection();
|
||||
conn.Open();
|
||||
using var cmd = new NpgsqlCommand("drop sequence if exists seq_specialisation; " +
|
||||
"drop sequence if exists seq_service; " +
|
||||
"drop sequence if exists seq_master; " +
|
||||
"drop sequence if exists seq_client; " +
|
||||
"drop sequence if exists seq_reception; " +
|
||||
"drop sequence if exists seq_cheque; " +
|
||||
"create sequence seq_specialisation increment by 1 start with 1 minvalue 1; " +
|
||||
"create sequence seq_service increment by 1 start with 1 minvalue 1; " +
|
||||
"create sequence seq_master increment by 1 start with 1 minvalue 1; " +
|
||||
"create sequence seq_client increment by 1 start with 1 minvalue 1; " +
|
||||
"create sequence seq_reception increment by 1 start with 1 minvalue 1; " +
|
||||
"create sequence seq_cheque increment by 1 start with 1 minvalue 1; " +
|
||||
"delete from specialisations; " +
|
||||
"delete from services; " +
|
||||
"delete from masters; " +
|
||||
"delete from clients; " +
|
||||
"delete from cheques;");
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
|
||||
public NpgsqlConnection GetConnection()
|
||||
{
|
||||
return new NpgsqlConnection("Host=127.0.0.1;Port=5555;Username=elina;Database=beauty_salon;Password=elina");
|
||||
}
|
||||
}
|
||||
}
|
@ -75,7 +75,7 @@ namespace BeautySalonDBModels.Implements
|
||||
{
|
||||
using var conn = GetConnection();
|
||||
conn.Open();
|
||||
using var cmd = new NpgsqlCommand("update master set specialisation_id = @specId, " +
|
||||
using var cmd = new NpgsqlCommand("update masters set specialisation_id = @specId, " +
|
||||
"fio = @fio where master_id = @id", conn);
|
||||
cmd.Parameters.AddWithValue("@specId", master.SpecialisationId);
|
||||
cmd.Parameters.AddWithValue("@fio", master.FIO);
|
||||
|
@ -77,7 +77,7 @@ namespace BeautySalonDBModels.Implements
|
||||
{
|
||||
using var conn = GetConnection();
|
||||
conn.Open();
|
||||
using var cmd = new NpgsqlCommand("update service set service_name = @name, " +
|
||||
using var cmd = new NpgsqlCommand("update services set service_name = @name, " +
|
||||
"price = @price, specialisation_id = @SpecialisationId where service_id = @id", conn);
|
||||
cmd.Parameters.AddWithValue("@name", service.ServiceName);
|
||||
cmd.Parameters.AddWithValue("@price", service.Price);
|
||||
@ -123,5 +123,29 @@ namespace BeautySalonDBModels.Implements
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
using var conn = GetConnection();
|
||||
conn.Open();
|
||||
using var cmd = new NpgsqlCommand("drop sequence if exists seq_specialisation; " +
|
||||
"drop sequence if exists seq_service; " +
|
||||
"drop sequence if exists seq_master; " +
|
||||
"drop sequence if exists seq_client; " +
|
||||
"drop sequence if exists seq_reception; " +
|
||||
"drop sequence if exists seq_cheque; " +
|
||||
"create sequence seq_specialisation increment by 1 start with 1 minvalue 1; " +
|
||||
"create sequence seq_service increment by 1 start with 1 minvalue 1; " +
|
||||
"create sequence seq_master increment by 1 start with 1 minvalue 1; " +
|
||||
"create sequence seq_client increment by 1 start with 1 minvalue 1; " +
|
||||
"create sequence seq_reception increment by 1 start with 1 minvalue 1; " +
|
||||
"create sequence seq_cheque increment by 1 start with 1 minvalue 1; " +
|
||||
"delete from specialisations; " +
|
||||
"delete from services; " +
|
||||
"delete from masters; " +
|
||||
"delete from clients; " +
|
||||
"delete from cheques;", conn);
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user