From 942fa52827cf3b1a7b74f7c491e4508b989877a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=95=D0=BB=D0=B5=D0=BD=D0=B0=20=D0=91=D0=B0=D0=BA=D0=B0?= =?UTF-8?q?=D0=BB=D1=8C=D1=81=D0=BA=D0=B0=D1=8F?= Date: Tue, 14 May 2024 23:08:28 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BD=D1=83=20=D0=B2=20=D0=BF=D1=80=D0=B8?= =?UTF-8?q?=D0=BD=D1=86=D0=B8=D0=BF=D0=B5=20=D0=BF=D0=BE=D1=87=D1=82=D0=B8?= =?UTF-8?q?=20=D0=B2=D1=81=D0=B5,=20=D0=BE=D1=81=D1=82=D0=B0=D0=BB=D0=BE?= =?UTF-8?q?=D1=81=D1=8C=20=D1=80=D0=B0=D0=B7=D0=BE=D0=B1=D1=80=D0=B0=D1=82?= =?UTF-8?q?=D1=8C=D1=81=D1=8F=20=D1=82=D0=BE=D0=BB=D1=8C=D0=BA=D0=BE=20?= =?UTF-8?q?=D1=81=20=D1=82=D0=B5=D0=BC,=20=D1=87=D1=82=D0=BE=D0=B1=D1=8B?= =?UTF-8?q?=20=D0=A4=D0=98=D0=9E=20=D0=BC=D0=B0=D1=81=D1=82=D0=B5=D1=80?= =?UTF-8?q?=D0=B0=20=D0=B8=20=D0=BD=D0=B0=D0=B7=D0=B2=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D1=83=D1=81=D0=BB=D1=83=D0=B3=D0=B8=20=D0=B2=D1=8B?= =?UTF-8?q?=D0=B2=D0=BE=D0=B4=D0=B8=D0=BB=D0=B8=D1=81=D1=8C=20=D0=B8=20?= =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D1=82=D1=8C=20=D0=BF=D0=BE?= =?UTF-8?q?=D0=B4=D1=81=D1=87=D0=B5=D1=82=20=D0=B2=D1=80=D0=B5=D0=BC=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BeautySalon/FormCheque.Designer.cs | 113 +++++++++++--- BeautySalon/BeautySalon/FormCheque.cs | 128 ++++++++++++++-- .../BeautySalon/FormCheques.Designer.cs | 10 +- BeautySalon/BeautySalon/FormCheques.cs | 17 +-- BeautySalon/BeautySalon/FormMain.Designer.cs | 7 - BeautySalon/BeautySalon/FormMain.cs | 9 -- .../BeautySalon/FormReception.Designer.cs | 143 ------------------ BeautySalon/BeautySalon/FormReception.cs | 121 --------------- BeautySalon/BeautySalon/FormReception.resx | 120 --------------- .../BeautySalon/FormReceptions.Designer.cs | 105 ------------- BeautySalon/BeautySalon/FormReceptions.cs | 98 ------------ BeautySalon/BeautySalon/FormReceptions.resx | 120 --------------- BeautySalon/BeautySalon/Program.cs | 4 - .../Implements/ChequeDatabase.cs | 56 +++++-- .../Implements/ReceptionDatabase.cs | 127 ---------------- .../BeautySalonDBModels/Models/Cheque.cs | 4 +- .../BeautySalonDBModels/Models/Client.cs | 5 + .../BeautySalonDBModels/Models/Master.cs | 2 +- .../BeautySalonDBModels/Models/Reception.cs | 12 -- .../BeautySalonDBModels/Models/Service.cs | 2 +- 20 files changed, 276 insertions(+), 927 deletions(-) delete mode 100644 BeautySalon/BeautySalon/FormReception.Designer.cs delete mode 100644 BeautySalon/BeautySalon/FormReception.cs delete mode 100644 BeautySalon/BeautySalon/FormReception.resx delete mode 100644 BeautySalon/BeautySalon/FormReceptions.Designer.cs delete mode 100644 BeautySalon/BeautySalon/FormReceptions.cs delete mode 100644 BeautySalon/BeautySalon/FormReceptions.resx delete mode 100644 BeautySalon/BeautySalonDBModels/Implements/ReceptionDatabase.cs delete mode 100644 BeautySalon/BeautySalonDBModels/Models/Reception.cs diff --git a/BeautySalon/BeautySalon/FormCheque.Designer.cs b/BeautySalon/BeautySalon/FormCheque.Designer.cs index 088df93..530c612 100644 --- a/BeautySalon/BeautySalon/FormCheque.Designer.cs +++ b/BeautySalon/BeautySalon/FormCheque.Designer.cs @@ -32,15 +32,20 @@ comboBoxClients = new ComboBox(); buttonCancel = new Button(); buttonSave = new Button(); - labelReception = new Label(); - comboBoxReceptions = new ComboBox(); + labelService = new Label(); + comboBoxServices = new ComboBox(); client = new Label(); + labelMaster = new Label(); + comboBoxMaster = new ComboBox(); + dateTimePickerDateReception = new DateTimePicker(); + labelPriceName = new Label(); + Price = new Label(); SuspendLayout(); // // labelPrice // labelPrice.AutoSize = true; - labelPrice.Location = new Point(19, 138); + labelPrice.Location = new Point(25, 254); labelPrice.Name = "labelPrice"; labelPrice.Size = new Size(99, 20); labelPrice.TabIndex = 21; @@ -48,67 +53,120 @@ // // comboBoxClients // + comboBoxClients.DropDownStyle = ComboBoxStyle.DropDownList; comboBoxClients.FormattingEnabled = true; - comboBoxClients.Location = new Point(176, 73); + comboBoxClients.Location = new Point(176, 180); comboBoxClients.Name = "comboBoxClients"; comboBoxClients.Size = new Size(290, 28); comboBoxClients.TabIndex = 20; // // buttonCancel // - buttonCancel.Location = new Point(327, 202); + buttonCancel.Location = new Point(333, 417); buttonCancel.Name = "buttonCancel"; buttonCancel.Size = new Size(133, 44); buttonCancel.TabIndex = 19; buttonCancel.Text = "Отмена"; buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; // // buttonSave // - buttonSave.Location = new Point(19, 202); + buttonSave.Location = new Point(25, 417); buttonSave.Name = "buttonSave"; buttonSave.Size = new Size(133, 44); buttonSave.TabIndex = 18; buttonSave.Text = "Сохранить"; buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; // - // labelReception + // labelService // - labelReception.AutoSize = true; - labelReception.Location = new Point(25, 23); - labelReception.Name = "labelReception"; - labelReception.Size = new Size(57, 20); - labelReception.TabIndex = 17; - labelReception.Text = "Прием"; + labelService.AutoSize = true; + labelService.Location = new Point(25, 23); + labelService.Name = "labelService"; + labelService.Size = new Size(54, 20); + labelService.TabIndex = 17; + labelService.Text = "Услуга"; // - // comboBoxReceptions + // comboBoxServices // - comboBoxReceptions.FormattingEnabled = true; - comboBoxReceptions.Location = new Point(176, 20); - comboBoxReceptions.Name = "comboBoxReceptions"; - comboBoxReceptions.Size = new Size(290, 28); - comboBoxReceptions.TabIndex = 16; + comboBoxServices.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxServices.FormattingEnabled = true; + comboBoxServices.Location = new Point(176, 20); + comboBoxServices.Name = "comboBoxServices"; + comboBoxServices.Size = new Size(290, 28); + comboBoxServices.TabIndex = 16; + comboBoxServices.SelectedIndexChanged += comboBoxServices_SelectedIndexChanged; // // client // client.AutoSize = true; - client.Location = new Point(25, 81); + client.Location = new Point(25, 188); client.Name = "client"; client.Size = new Size(58, 20); client.TabIndex = 15; client.Text = "Клиент"; // + // labelMaster + // + labelMaster.AutoSize = true; + labelMaster.Location = new Point(25, 103); + labelMaster.Name = "labelMaster"; + labelMaster.Size = new Size(60, 20); + labelMaster.TabIndex = 23; + labelMaster.Text = "Мастер"; + // + // comboBoxMaster + // + comboBoxMaster.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxMaster.FormattingEnabled = true; + comboBoxMaster.Location = new Point(176, 100); + comboBoxMaster.Name = "comboBoxMaster"; + comboBoxMaster.Size = new Size(290, 28); + comboBoxMaster.TabIndex = 22; + // + // dateTimePickerDateReception + // + dateTimePickerDateReception.Location = new Point(176, 254); + dateTimePickerDateReception.Name = "dateTimePickerDateReception"; + dateTimePickerDateReception.Size = new Size(290, 27); + dateTimePickerDateReception.TabIndex = 24; + // + // labelPriceName + // + labelPriceName.AutoSize = true; + labelPriceName.Location = new Point(142, 345); + labelPriceName.Name = "labelPriceName"; + labelPriceName.Size = new Size(45, 20); + labelPriceName.TabIndex = 25; + labelPriceName.Text = "Цена"; + // + // Price + // + Price.AutoSize = true; + Price.Location = new Point(286, 345); + Price.Name = "Price"; + Price.Size = new Size(115, 20); + Price.TabIndex = 26; + Price.Text = "0,0 тыщ рублей"; + // // FormCheque // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(499, 266); + ClientSize = new Size(499, 482); + Controls.Add(Price); + Controls.Add(labelPriceName); + Controls.Add(dateTimePickerDateReception); + Controls.Add(labelMaster); + Controls.Add(comboBoxMaster); Controls.Add(labelPrice); Controls.Add(comboBoxClients); Controls.Add(buttonCancel); Controls.Add(buttonSave); - Controls.Add(labelReception); - Controls.Add(comboBoxReceptions); + Controls.Add(labelService); + Controls.Add(comboBoxServices); Controls.Add(client); Name = "FormCheque"; Text = "Чек"; @@ -122,8 +180,13 @@ private ComboBox comboBoxClients; private Button buttonCancel; private Button buttonSave; - private Label labelReception; - private ComboBox comboBoxReceptions; + private Label labelService; + private ComboBox comboBoxServices; private Label client; + private Label labelMaster; + private ComboBox comboBoxMaster; + private DateTimePicker dateTimePickerDateReception; + private Label labelPriceName; + private Label Price; } } \ No newline at end of file diff --git a/BeautySalon/BeautySalon/FormCheque.cs b/BeautySalon/BeautySalon/FormCheque.cs index e9d7ec2..016522a 100644 --- a/BeautySalon/BeautySalon/FormCheque.cs +++ b/BeautySalon/BeautySalon/FormCheque.cs @@ -1,27 +1,135 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; +using BeautySalonDBModels.Implements; +using BeautySalonDBModels.Models; +using BeautySalonDBModels; +using System; namespace BeautySalon { public partial class FormCheque : Form { + private List services; + private List masters; + private List clients; + private readonly AbstractWorkWithStorage clientStorage; + private readonly AbstractWorkWithStorage serviceStorage; + private readonly AbstractWorkWithStorage masterStorage; + private readonly AbstractWorkWithStorage chequeStorage; + + private int? _id; public int Id { set { _id = value; } } - public FormCheque() + public FormCheque(AbstractWorkWithStorage clientStorage, + AbstractWorkWithStorage serviceStorage, + AbstractWorkWithStorage masterStorage, + AbstractWorkWithStorage chequeStorage) { + this.clientStorage = clientStorage; + this.serviceStorage = serviceStorage; + this.masterStorage = masterStorage; + this.chequeStorage = chequeStorage; + InitializeComponent(); + + comboBoxMaster.Enabled = false; + + services = serviceStorage.GetObjects(); + foreach (Service service in services) + { + comboBoxServices.Items.Add(service).ToString(); + } + + clients = clientStorage.GetObjects(); + foreach (Client client in clients) + { + comboBoxClients.Items.Add(client).ToString(); + } + } + + private void FormReception_Load(object sender, EventArgs e) + { + if (_id != null) + { + try + { + var cheque = chequeStorage.GetObject(_id.Value); + + if (cheque != null) + { + dateTimePickerDateReception.Value = cheque.DateReception; + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } + + private void buttonSave_Click(object sender, EventArgs e) + { + + try + { + if (_id != null) + { + var newCheque = new Cheque + { + ChequeId = _id ?? 0, + ServiceId = (comboBoxServices.SelectedItem as Service)!.ServiceId, + MasterId = (comboBoxMaster.SelectedItem as Master)!.MasterId, + ClientId = (comboBoxClients.SelectedItem as Client)!.ClientId, + DateReception = dateTimePickerDateReception.Value, + Price = Convert.ToDouble((comboBoxServices.SelectedItem as Service)!.Price.ToString()) + }; + chequeStorage.Update(newCheque); + } + else + { + var newCheque = new Cheque + { + ServiceId = (comboBoxServices.SelectedItem as Service)!.ServiceId, + MasterId = (comboBoxMaster.SelectedItem as Master)!.MasterId, + ClientId = (comboBoxClients.SelectedItem as Client)!.ClientId, + DateReception = dateTimePickerDateReception.Value, + Price = Convert.ToDouble((comboBoxServices.SelectedItem as Service)!.Price.ToString()) + }; + chequeStorage.Add(newCheque); + } + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception) + { + throw; + } + } + + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; Close(); + } + + private void comboBoxServices_SelectedIndexChanged(object sender, EventArgs e) + { + comboBoxMaster.Items.Clear(); + if (comboBoxServices.SelectedIndex > -1) + { + Price.Text = (comboBoxServices.SelectedItem as Service)!.Price.ToString() + " тыщ долларов :)"; + comboBoxMaster.Enabled = true; + int serviceId = (comboBoxServices.SelectedItem as Service)!.ServiceId; + ServiceDatabase sdb = new ServiceDatabase(); + List mss = sdb.GetFilteredListByService(serviceId); + foreach (Master master in mss) + { + comboBoxMaster.Items.Add(master).ToString(); + } + } } } } diff --git a/BeautySalon/BeautySalon/FormCheques.Designer.cs b/BeautySalon/BeautySalon/FormCheques.Designer.cs index 16b02b2..1486d3c 100644 --- a/BeautySalon/BeautySalon/FormCheques.Designer.cs +++ b/BeautySalon/BeautySalon/FormCheques.Designer.cs @@ -37,7 +37,7 @@ // // buttonDelete // - buttonDelete.Location = new Point(576, 352); + buttonDelete.Location = new Point(928, 352); buttonDelete.Name = "buttonDelete"; buttonDelete.Size = new Size(147, 56); buttonDelete.TabIndex = 13; @@ -56,12 +56,12 @@ dataGridView.RowHeadersVisible = false; dataGridView.RowHeadersWidth = 51; dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; - dataGridView.Size = new Size(493, 450); + dataGridView.Size = new Size(880, 450); dataGridView.TabIndex = 10; // // buttonUpdate // - buttonUpdate.Location = new Point(576, 190); + buttonUpdate.Location = new Point(928, 190); buttonUpdate.Name = "buttonUpdate"; buttonUpdate.Size = new Size(147, 56); buttonUpdate.TabIndex = 15; @@ -71,7 +71,7 @@ // // buttonCreate // - buttonCreate.Location = new Point(576, 43); + buttonCreate.Location = new Point(928, 43); buttonCreate.Name = "buttonCreate"; buttonCreate.Size = new Size(147, 56); buttonCreate.TabIndex = 14; @@ -83,7 +83,7 @@ // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(801, 450); + ClientSize = new Size(1120, 450); Controls.Add(buttonUpdate); Controls.Add(buttonCreate); Controls.Add(buttonDelete); diff --git a/BeautySalon/BeautySalon/FormCheques.cs b/BeautySalon/BeautySalon/FormCheques.cs index e18555a..dff161c 100644 --- a/BeautySalon/BeautySalon/FormCheques.cs +++ b/BeautySalon/BeautySalon/FormCheques.cs @@ -46,7 +46,6 @@ namespace BeautySalon { List cheques = chequeStorage.GetObjects(); ChequeDatabase cdb = new ChequeDatabase(); - ReceptionDatabase rdb = new ReceptionDatabase(); dataGridView.Rows.Clear(); @@ -55,20 +54,20 @@ namespace BeautySalon dataGridView.Columns.Add("ChequeId", "ID"); dataGridView.Columns.Add("ClientFIO", "ФИО клиента"); dataGridView.Columns.Add("ServiceName", "Название услуги"); + dataGridView.Columns.Add("MasterFIO", "ФИО мастера"); + dataGridView.Columns.Add("DateReception", "Дата оказания услуги"); dataGridView.Columns.Add("Price", "Цена"); } foreach (Cheque cheque in cheques) { - var reception = rdb.GetObject(cheque.ReceptionId); - var client = rdb.GetObject(cheque.ClientId); - if (reception != null && client != null) - { - string serviceName = rdb.GetServiceName(reception); - string clientFIO = cdb.GetClientFIO(cheque); - double servicePrice = rdb.GetServicePrice(reception); + var clientFIO = cdb.GetClientFIO(cheque); + var serviceName = cdb.GetServiceName(cheque); + var masterFIO = cdb.GetMasterFIO(cheque); - dataGridView.Rows.Add(cheque.ChequeId, clientFIO, serviceName, servicePrice); + if(clientFIO != null && serviceName != null && masterFIO != null) + { + dataGridView.Rows.Add(cheque.ChequeId, clientFIO, serviceName, masterFIO, cheque.DateReception, cheque.Price); } } dataGridView.Columns["ChequeId"].Visible = false; diff --git a/BeautySalon/BeautySalon/FormMain.Designer.cs b/BeautySalon/BeautySalon/FormMain.Designer.cs index 8209e50..f443097 100644 --- a/BeautySalon/BeautySalon/FormMain.Designer.cs +++ b/BeautySalon/BeautySalon/FormMain.Designer.cs @@ -76,13 +76,6 @@ добавитьToolStripMenuItem1.Text = "Клиенты"; добавитьToolStripMenuItem1.Click += добавитьToolStripMenuItem1_Click; // - // создатьПриемToolStripMenuItem - // - создатьПриемToolStripMenuItem.Name = "создатьПриемToolStripMenuItem"; - создатьПриемToolStripMenuItem.Size = new Size(82, 24); - создатьПриемToolStripMenuItem.Text = "Приемы"; - создатьПриемToolStripMenuItem.Click += создатьПриемToolStripMenuItem_Click; - // // посмотретьЧекиToolStripMenuItem // посмотретьЧекиToolStripMenuItem.Name = "посмотретьЧекиToolStripMenuItem"; diff --git a/BeautySalon/BeautySalon/FormMain.cs b/BeautySalon/BeautySalon/FormMain.cs index 9097fd8..4b0bd45 100644 --- a/BeautySalon/BeautySalon/FormMain.cs +++ b/BeautySalon/BeautySalon/FormMain.cs @@ -67,15 +67,6 @@ namespace BeautySalon } } - private void создатьПриемToolStripMenuItem_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormReceptions)); - if (service is FormReceptions form) - { - form.ShowDialog(); - } - } - private void посмотретьЧекиToolStripMenuItem_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormCheques)); diff --git a/BeautySalon/BeautySalon/FormReception.Designer.cs b/BeautySalon/BeautySalon/FormReception.Designer.cs deleted file mode 100644 index 82fdb0d..0000000 --- a/BeautySalon/BeautySalon/FormReception.Designer.cs +++ /dev/null @@ -1,143 +0,0 @@ -namespace BeautySalon -{ - partial class FormReception - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - buttonCancel = new Button(); - buttonSave = new Button(); - labelService = new Label(); - comboBoxService = new ComboBox(); - Master = new Label(); - comboBoxMaster = new ComboBox(); - labelDateReception = new Label(); - dateTimePickerDateReception = new DateTimePicker(); - SuspendLayout(); - // - // buttonCancel - // - buttonCancel.Location = new Point(329, 208); - buttonCancel.Name = "buttonCancel"; - buttonCancel.Size = new Size(133, 44); - buttonCancel.TabIndex = 11; - buttonCancel.Text = "Отмена"; - buttonCancel.UseVisualStyleBackColor = true; - buttonCancel.Click += buttonCancel_Click; - // - // buttonSave - // - buttonSave.Location = new Point(21, 208); - buttonSave.Name = "buttonSave"; - buttonSave.Size = new Size(133, 44); - buttonSave.TabIndex = 10; - buttonSave.Text = "Сохранить"; - buttonSave.UseVisualStyleBackColor = true; - buttonSave.Click += buttonSave_Click; - // - // labelService - // - labelService.AutoSize = true; - labelService.Location = new Point(27, 29); - labelService.Name = "labelService"; - labelService.Size = new Size(57, 20); - labelService.TabIndex = 9; - labelService.Text = "Услуга:"; - // - // comboBoxService - // - comboBoxService.FormattingEnabled = true; - comboBoxService.Location = new Point(178, 26); - comboBoxService.Name = "comboBoxService"; - comboBoxService.Size = new Size(290, 28); - comboBoxService.TabIndex = 8; - comboBoxService.SelectedIndexChanged += comboBoxService_SelectedIndexChanged; - // - // Master - // - Master.AutoSize = true; - Master.Location = new Point(27, 87); - Master.Name = "Master"; - Master.Size = new Size(63, 20); - Master.TabIndex = 7; - Master.Text = "Мастер:"; - // - // comboBoxMaster - // - comboBoxMaster.FormattingEnabled = true; - comboBoxMaster.Location = new Point(178, 79); - comboBoxMaster.Name = "comboBoxMaster"; - comboBoxMaster.Size = new Size(290, 28); - comboBoxMaster.TabIndex = 12; - // - // labelDateReception - // - labelDateReception.AutoSize = true; - labelDateReception.Location = new Point(21, 144); - labelDateReception.Name = "labelDateReception"; - labelDateReception.Size = new Size(99, 20); - labelDateReception.TabIndex = 13; - labelDateReception.Text = "Дата приема"; - // - // dateTimePickerDateReception - // - dateTimePickerDateReception.Location = new Point(178, 139); - dateTimePickerDateReception.Name = "dateTimePickerDateReception"; - dateTimePickerDateReception.Size = new Size(290, 27); - dateTimePickerDateReception.TabIndex = 14; - // - // FormReception - // - AutoScaleDimensions = new SizeF(8F, 20F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(493, 280); - Controls.Add(dateTimePickerDateReception); - Controls.Add(labelDateReception); - Controls.Add(comboBoxMaster); - Controls.Add(buttonCancel); - Controls.Add(buttonSave); - Controls.Add(labelService); - Controls.Add(comboBoxService); - Controls.Add(Master); - Name = "FormReception"; - Text = "Прием"; - Load += FormReception_Load; - ResumeLayout(false); - PerformLayout(); - } - - #endregion - - private Button buttonCancel; - private Button buttonSave; - private Label labelService; - private ComboBox comboBoxService; - private Label Master; - private ComboBox comboBoxMaster; - private Label labelDateReception; - private DateTimePicker dateTimePickerDateReception; - } -} \ No newline at end of file diff --git a/BeautySalon/BeautySalon/FormReception.cs b/BeautySalon/BeautySalon/FormReception.cs deleted file mode 100644 index b034172..0000000 --- a/BeautySalon/BeautySalon/FormReception.cs +++ /dev/null @@ -1,121 +0,0 @@ -using BeautySalonDBModels; -using BeautySalonDBModels.Implements; -using BeautySalonDBModels.Models; - -namespace BeautySalon -{ - public partial class FormReception : Form - { - private List services; - private List masters; - private readonly AbstractWorkWithStorage receptionStorage; - private readonly AbstractWorkWithStorage serviceStorage; - private readonly AbstractWorkWithStorage masterStorage; - - - private int? _id; - public int Id - { - set { _id = value; } - } - - public FormReception(AbstractWorkWithStorage receptionStorage, - AbstractWorkWithStorage serviceStorage, - AbstractWorkWithStorage masterStorage) - { - this.receptionStorage = receptionStorage; - this.serviceStorage = serviceStorage; - this.masterStorage = masterStorage; - - InitializeComponent(); - - comboBoxMaster.Enabled = false; - - services = serviceStorage.GetObjects(); - foreach (Service service in services) - { - comboBoxService.Items.Add(service).ToString(); - } - } - - private void FormReception_Load(object sender, EventArgs e) - { - if (_id != null) - { - try - { - var reception = receptionStorage.GetObject(_id.Value); - - if (reception != null) - { - dateTimePickerDateReception.Value = reception.DateReception; - } - } - catch (Exception ex) - { - MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, - MessageBoxIcon.Error); - } - } - } - - private void buttonSave_Click(object sender, EventArgs e) - { - - try - { - if (_id != null) - { - var newReception = new Reception - { - ReceptionId = _id ?? 0, - ServiceId = (comboBoxService.SelectedItem as Service)!.ServiceId, - MasterId = (comboBoxMaster.SelectedItem as Master)!.MasterId, - DateReception = dateTimePickerDateReception.Value, - - }; - receptionStorage.Update(newReception); - } - else - { - var newReception = new Reception - { - ServiceId = (comboBoxService.SelectedItem as Service)!.ServiceId, - MasterId = (comboBoxMaster.SelectedItem as Master)!.MasterId, - DateReception = dateTimePickerDateReception.Value, - }; - receptionStorage.Add(newReception); - } - DialogResult = DialogResult.OK; - Close(); - } - catch (Exception) - { - - throw; - } - - } - - private void buttonCancel_Click(object sender, EventArgs e) - { - DialogResult = DialogResult.Cancel; Close(); - } - - private void comboBoxService_SelectedIndexChanged(object sender, EventArgs e) - { - comboBoxMaster.Items.Clear(); - if (comboBoxService.SelectedIndex > -1) - { - comboBoxMaster.Enabled = true; - int serviceId = (comboBoxService.SelectedItem as Service)!.ServiceId; - ServiceDatabase sdb = new ServiceDatabase(); - List mss = sdb.GetFilteredListByService(serviceId); - foreach (Master master in mss) - { - comboBoxMaster.Items.Add(master).ToString(); - } - } - } - } -} diff --git a/BeautySalon/BeautySalon/FormReception.resx b/BeautySalon/BeautySalon/FormReception.resx deleted file mode 100644 index af32865..0000000 --- a/BeautySalon/BeautySalon/FormReception.resx +++ /dev/null @@ -1,120 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - \ No newline at end of file diff --git a/BeautySalon/BeautySalon/FormReceptions.Designer.cs b/BeautySalon/BeautySalon/FormReceptions.Designer.cs deleted file mode 100644 index ff3c7db..0000000 --- a/BeautySalon/BeautySalon/FormReceptions.Designer.cs +++ /dev/null @@ -1,105 +0,0 @@ -namespace BeautySalon -{ - partial class FormReceptions - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - buttonDelete = new Button(); - buttonUpdate = new Button(); - buttonCreate = new Button(); - dataGridView = new DataGridView(); - ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); - SuspendLayout(); - // - // buttonDelete - // - buttonDelete.Location = new Point(515, 363); - buttonDelete.Name = "buttonDelete"; - buttonDelete.Size = new Size(147, 56); - buttonDelete.TabIndex = 13; - buttonDelete.Text = "Уничтожить..."; - buttonDelete.UseVisualStyleBackColor = true; - buttonDelete.Click += buttonDelete_Click; - // - // buttonUpdate - // - buttonUpdate.Location = new Point(515, 193); - buttonUpdate.Name = "buttonUpdate"; - buttonUpdate.Size = new Size(147, 56); - buttonUpdate.TabIndex = 12; - buttonUpdate.Text = "Корректровать"; - buttonUpdate.UseVisualStyleBackColor = true; - buttonUpdate.Click += buttonUpdate_Click; - // - // buttonCreate - // - buttonCreate.Location = new Point(515, 32); - buttonCreate.Name = "buttonCreate"; - buttonCreate.Size = new Size(147, 56); - buttonCreate.TabIndex = 11; - buttonCreate.Text = "Добавить"; - buttonCreate.UseVisualStyleBackColor = true; - buttonCreate.Click += buttonCreate_Click; - // - // dataGridView - // - dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; - dataGridView.BackgroundColor = SystemColors.GradientInactiveCaption; - dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; - dataGridView.Dock = DockStyle.Left; - dataGridView.Location = new Point(0, 0); - dataGridView.Name = "dataGridView"; - dataGridView.RowHeadersVisible = false; - dataGridView.RowHeadersWidth = 51; - dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect; - dataGridView.Size = new Size(470, 450); - dataGridView.TabIndex = 10; - // - // FormReceptions - // - AutoScaleDimensions = new SizeF(8F, 20F); - AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(712, 450); - Controls.Add(buttonDelete); - Controls.Add(buttonUpdate); - Controls.Add(buttonCreate); - Controls.Add(dataGridView); - Name = "FormReceptions"; - Text = "Приемы"; - Load += FormReceptions_Load; - ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); - ResumeLayout(false); - } - - #endregion - - private Button buttonDelete; - private Button buttonUpdate; - private Button buttonCreate; - private DataGridView dataGridView; - } -} \ No newline at end of file diff --git a/BeautySalon/BeautySalon/FormReceptions.cs b/BeautySalon/BeautySalon/FormReceptions.cs deleted file mode 100644 index 7d4dee2..0000000 --- a/BeautySalon/BeautySalon/FormReceptions.cs +++ /dev/null @@ -1,98 +0,0 @@ -using BeautySalonDBModels.Models; -using BeautySalonDBModels; -using BeautySalonDBModels.Implements; - -namespace BeautySalon -{ - public partial class FormReceptions : Form - { - - private int? _id; - public int Id - { - set { _id = value; } - } - - private readonly AbstractWorkWithStorage receptionStorage; - private readonly AbstractWorkWithStorage serviceStorage; - private readonly AbstractWorkWithStorage masterStorage; - - public FormReceptions(AbstractWorkWithStorage receptionStorage, - AbstractWorkWithStorage serviceStorage, - AbstractWorkWithStorage masterStorage) - { - this.receptionStorage = receptionStorage; - this.serviceStorage = serviceStorage; - this.masterStorage = masterStorage; - InitializeComponent(); - } - - private void LoadData() - { - List receptions = receptionStorage.GetObjects(); - ReceptionDatabase rdb = new ReceptionDatabase(); - - dataGridView.Rows.Clear(); - - if (dataGridView.ColumnCount == 0) - { - dataGridView.Columns.Add("ReceptionId", "Id"); - dataGridView.Columns.Add("Master", "ФИО мастера"); - dataGridView.Columns.Add("Service", "Услуга"); - dataGridView.Columns.Add("Date", "Дата приема"); - } - - foreach (Reception reception in receptions) - { - string masterFIO = rdb.GetMasterFio(reception); - string serviceName = rdb.GetServiceName(reception); - dataGridView.Rows.Add(reception.ReceptionId, masterFIO, serviceName, reception.DateReception); - } - dataGridView.Columns["ReceptionId"].Visible = false; - } - - private void buttonCreate_Click(object sender, EventArgs e) - { - var service = Program.ServiceProvider?.GetService(typeof(FormReception)); - if(service is FormReception form) - { - if(form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } - } - } - - private void buttonUpdate_Click(object sender, EventArgs e) - { - if (dataGridView.SelectedRows.Count == 1) - { - var service = Program.ServiceProvider?.GetService(typeof(FormReception)); - if (service is FormReception form) - { - int rowIndex = dataGridView.CurrentCell.RowIndex; - form.Id = (int)dataGridView.Rows[rowIndex].Cells["ReceptionId"].Value; - if (form.ShowDialog() == DialogResult.OK) - { - LoadData(); - } - } - } - } - - private void buttonDelete_Click(object sender, EventArgs e) - { - if(dataGridView.SelectedRows.Count == 1) - { - int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["ReceptionId"].Value); - receptionStorage.Remove(id); - LoadData(); - } - } - - private void FormReceptions_Load(object sender, EventArgs e) - { - LoadData(); - } - } -} diff --git a/BeautySalon/BeautySalon/FormReceptions.resx b/BeautySalon/BeautySalon/FormReceptions.resx deleted file mode 100644 index af32865..0000000 --- a/BeautySalon/BeautySalon/FormReceptions.resx +++ /dev/null @@ -1,120 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - \ No newline at end of file diff --git a/BeautySalon/BeautySalon/Program.cs b/BeautySalon/BeautySalon/Program.cs index 61232f4..c7690a8 100644 --- a/BeautySalon/BeautySalon/Program.cs +++ b/BeautySalon/BeautySalon/Program.cs @@ -42,7 +42,6 @@ namespace BeautySalon services.AddSingleton, MasterDatabase>(); services.AddSingleton, ChequeDatabase>(); services.AddSingleton, ClientDatabase>(); - services.AddSingleton, ReceptionDatabase>(); services.AddSingleton, ServiceDatabase>(); @@ -59,9 +58,6 @@ namespace BeautySalon services.AddTransient(); services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); services.AddTransient(); diff --git a/BeautySalon/BeautySalonDBModels/Implements/ChequeDatabase.cs b/BeautySalon/BeautySalonDBModels/Implements/ChequeDatabase.cs index ae1aeb8..1a8efa6 100644 --- a/BeautySalon/BeautySalonDBModels/Implements/ChequeDatabase.cs +++ b/BeautySalon/BeautySalonDBModels/Implements/ChequeDatabase.cs @@ -14,11 +14,13 @@ namespace BeautySalonDBModels.Implements { using var conn = GetConnection(); conn.Open(); - using var cmd = new NpgsqlCommand("INSERT INTO cheques (cheque_id, client_id, reception_id, price)" + - " VALUES ((nextval('seq_cheque')), @ClientId, @ReceptionId. @Price)", conn); + using var cmd = new NpgsqlCommand("INSERT INTO cheques (cheque_id, client_id, master_id, service_id, price, date_reception)" + + " VALUES (nextval('seq_cheque'), @ClientId, @master_id, @service_id, @Price, @DateReception)", conn); cmd.Parameters.AddWithValue("@ClientId", cheque.ClientId); - cmd.Parameters.AddWithValue("@ReceptionId", cheque.ReceptionId); + cmd.Parameters.AddWithValue("@master_id", cheque.MasterId); + cmd.Parameters.AddWithValue("@service_id", cheque.ServiceId); cmd.Parameters.AddWithValue("@Price", cheque.Price); + cmd.Parameters.AddWithValue("@DateReception", cheque.DateReception); cmd.ExecuteNonQuery(); } @@ -35,8 +37,10 @@ namespace BeautySalonDBModels.Implements { ChequeId = reader.GetInt32(0), ClientId = reader.GetInt32(1), - ReceptionId = reader.GetInt32(2), - Price = reader.GetDouble(3) + MasterId = reader.GetInt32(2), + ServiceId = reader.GetInt32(3), + Price = reader.GetDouble(4), + DateReception = reader.GetDateTime(5) }; } return null; @@ -55,8 +59,10 @@ namespace BeautySalonDBModels.Implements { ChequeId = reader.GetInt32(0), ClientId = reader.GetInt32(1), - ReceptionId = reader.GetInt32(2), - Price = reader.GetDouble(3) + MasterId = reader.GetInt32(2), + ServiceId = reader.GetInt32(3), + Price = reader.GetDouble(4), + DateReception = reader.GetDateTime(5) }); } return cheques; @@ -78,11 +84,13 @@ namespace BeautySalonDBModels.Implements using var conn = GetConnection(); conn.Open(); using var cmd = new NpgsqlCommand("update cheques set client_id = @ClientId, " + - "reception_id = @ReceptionId, price = @Price where cheque_id = @ChequeId", conn); + "master_id = @MasterId, service_id = @ServiceId, price = @Price, date_reception = @DateReception where cheque_id = @ChequeId", conn); cmd.Parameters.AddWithValue("@ClientId", cheque.ClientId); - cmd.Parameters.AddWithValue("@ReceptionId", cheque.ReceptionId); + cmd.Parameters.AddWithValue("@MasterId", cheque.MasterId); + cmd.Parameters.AddWithValue("@ServiceId", cheque.ServiceId); cmd.Parameters.AddWithValue("@ChequeId", cheque.ChequeId); cmd.Parameters.AddWithValue("@Price", cheque.Price); + cmd.Parameters.AddWithValue("@DateReception", cheque.DateReception); cmd.ExecuteNonQuery(); } @@ -100,5 +108,35 @@ namespace BeautySalonDBModels.Implements } return string.Empty; } + + public string GetMasterFIO(Cheque cheque) + { + MasterDatabase db = new MasterDatabase(); + + int masterId = cheque.MasterId; + + List masters = db.GetObjects(); + + foreach (Master c in masters) + { + if (c.MasterId == masterId) return c.FIO.ToString(); + } + return string.Empty; + } + + public string GetServiceName(Cheque cheque) + { + ServiceDatabase db = new ServiceDatabase(); + + int serviceId = cheque.ServiceId; + + List service = db.GetObjects(); + + foreach (Service s in service) + { + if (s.ServiceId == serviceId) return s.ServiceName.ToString(); + } + return string.Empty; + } } } diff --git a/BeautySalon/BeautySalonDBModels/Implements/ReceptionDatabase.cs b/BeautySalon/BeautySalonDBModels/Implements/ReceptionDatabase.cs deleted file mode 100644 index de30c3d..0000000 --- a/BeautySalon/BeautySalonDBModels/Implements/ReceptionDatabase.cs +++ /dev/null @@ -1,127 +0,0 @@ -using BeautySalonDBModels.Models; -using Npgsql; - -namespace BeautySalonDBModels.Implements -{ - public class ReceptionDatabase : AbstractWorkWithStorage - { - public override void Add(Reception reception) - { - using var conn = GetConnection(); - conn.Open(); - using var cmd = new NpgsqlCommand("INSERT INTO receptions (reception_id, master_id, service_id, date_reception) " + - "VALUES ((nextval('seq_reception')), @MasterId, @ServiceId, @DateReception)", conn); - cmd.Parameters.AddWithValue("@MasterId", reception.MasterId); - cmd.Parameters.AddWithValue("@ServiceId", reception.ServiceId); - cmd.Parameters.AddWithValue("@DateReception", reception.DateReception); - cmd.ExecuteNonQuery(); - } - - public override Reception? GetObject(int id) - { - using var conn = GetConnection(); - conn.Open(); - using var cmd = new NpgsqlCommand("SELECT * FROM receptions WHERE reception_id = @id", conn); - cmd.Parameters.AddWithValue("@id", id); - using var reader = cmd.ExecuteReader(); - if (reader.Read()) - { - return new Reception - { - ReceptionId = reader.GetInt32(0), - MasterId = reader.GetInt32(1), - ServiceId = reader.GetInt32(2), - DateReception = reader.GetDateTime(3) - }; - } - return null; - } - - public override List GetObjects() - { - var receptions = new List(); - using var conn = GetConnection(); - conn.Open(); - using var cmd = new NpgsqlCommand("SELECT * FROM receptions order by reception_id", conn); - using var reader = cmd.ExecuteReader(); - while (reader.Read()) - { - receptions.Add(new Reception - { - ReceptionId = reader.GetInt32(0), - MasterId = reader.GetInt32(1), - ServiceId = reader.GetInt32(2), - DateReception = reader.GetDateTime(3) - }); - } - return receptions; - } - - public override Reception? Remove(int id) - { - var reception = GetObject(id); - using var conn = GetConnection(); - conn.Open(); - using var cmd = new NpgsqlCommand("delete from receptions where reception_id = @id", conn); - cmd.Parameters.AddWithValue("@id", id); - cmd.ExecuteNonQuery(); - return reception; - } - - public override void Update(Reception reception) - { - using var conn = GetConnection(); - conn.Open(); - using var cmd = new NpgsqlCommand("update receptions set master_id = @MasterId, " + - "service_id = @ServiceId, date_reception = @DateReception where reception_id = @ReceptionId", conn); - cmd.Parameters.AddWithValue("@MasterId", reception.MasterId); - cmd.Parameters.AddWithValue("@ServiceId", reception.ServiceId); - cmd.Parameters.AddWithValue("@DateReception", reception.DateReception); - cmd.Parameters.AddWithValue("@ReceptionId", reception.ReceptionId); - - cmd.ExecuteNonQuery(); - } - - public string GetMasterFio(Reception reception) - { - MasterDatabase db = new MasterDatabase(); - int masterId = reception.MasterId; - - List masters = db.GetObjects(); - - foreach (Master master in masters) - { - if (master.MasterId == masterId) return master.FIO.ToString(); - } - return string.Empty; - } - - public string GetServiceName(Reception reception) - { - ServiceDatabase db = new ServiceDatabase(); - int serviceId = reception.ServiceId; - - List services = db.GetObjects(); - - foreach (Service service in services) - { - if (service.ServiceId == serviceId) return service.ServiceName.ToString(); - } - return string.Empty; - } - - public double GetServicePrice(Reception reception) - { - ServiceDatabase db = new ServiceDatabase(); - int serviceId = reception.ServiceId; - - List services = db.GetObjects(); - - foreach (Service service in services) - { - if (service.ServiceId == serviceId) return service.Price; - } - return 0; - } - } -} diff --git a/BeautySalon/BeautySalonDBModels/Models/Cheque.cs b/BeautySalon/BeautySalonDBModels/Models/Cheque.cs index 9b7bebd..c66e613 100644 --- a/BeautySalon/BeautySalonDBModels/Models/Cheque.cs +++ b/BeautySalon/BeautySalonDBModels/Models/Cheque.cs @@ -4,7 +4,9 @@ { public int ChequeId { get; set; } public int ClientId { get; set; } - public int ReceptionId { get; set; } + public int ServiceId { get; set; } + public int MasterId { get; set; } + public DateTime DateReception { get; set; } public double Price { get; set; } } } diff --git a/BeautySalon/BeautySalonDBModels/Models/Client.cs b/BeautySalon/BeautySalonDBModels/Models/Client.cs index 9a9ef95..f6420c8 100644 --- a/BeautySalon/BeautySalonDBModels/Models/Client.cs +++ b/BeautySalon/BeautySalonDBModels/Models/Client.cs @@ -5,5 +5,10 @@ public int ClientId { get; set; } public string FIO { get; set; } = string.Empty; public int Age { get; set; } + + public override string ToString() + { + return FIO.ToString(); + } } } diff --git a/BeautySalon/BeautySalonDBModels/Models/Master.cs b/BeautySalon/BeautySalonDBModels/Models/Master.cs index d77c0ef..a56b161 100644 --- a/BeautySalon/BeautySalonDBModels/Models/Master.cs +++ b/BeautySalon/BeautySalonDBModels/Models/Master.cs @@ -8,7 +8,7 @@ public override string ToString() { - return FIO; + return FIO.ToString(); } } } diff --git a/BeautySalon/BeautySalonDBModels/Models/Reception.cs b/BeautySalon/BeautySalonDBModels/Models/Reception.cs deleted file mode 100644 index a0d9f93..0000000 --- a/BeautySalon/BeautySalonDBModels/Models/Reception.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System.Data.SqlTypes; - -namespace BeautySalonDBModels.Models -{ - public class Reception - { - public int ReceptionId { get; set; } - public int MasterId { get; set; } - public int ServiceId { get; set; } - public DateTime DateReception { get; set; } - } -} diff --git a/BeautySalon/BeautySalonDBModels/Models/Service.cs b/BeautySalon/BeautySalonDBModels/Models/Service.cs index 709e3fb..a223a1b 100644 --- a/BeautySalon/BeautySalonDBModels/Models/Service.cs +++ b/BeautySalon/BeautySalonDBModels/Models/Service.cs @@ -9,7 +9,7 @@ public override string ToString() { - return ServiceName; + return ServiceName.ToString(); } } }