From 77a0ad270821eac82f8e870b36eee3caf092f972 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: Wed, 8 May 2024 03:05:15 +0400 Subject: [PATCH] =?UTF-8?q?=D1=82=D0=B0=D0=BA,=20=D0=B4=D0=BE=D0=B1=D0=B0?= =?UTF-8?q?=D0=B2=D0=B8=D0=BB=D0=B0=20=D1=84=D0=BE=D1=80=D0=BC=D1=8B=20?= =?UTF-8?q?=D1=83=D1=81=D0=BB=D1=83=D0=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit не работает пока что добавление --- BeautySalon/BeautySalon/FormMain.Designer.cs | 3 + BeautySalon/BeautySalon/FormMain.cs | 44 ++++++- BeautySalon/BeautySalon/FormMasters.cs | 9 -- .../BeautySalon/FormService.Designer.cs | 112 +++++++++++++++++- BeautySalon/BeautySalon/FormService.cs | 91 ++++++++++++-- BeautySalon/BeautySalon/FormService.resx | 50 ++++---- .../BeautySalon/FormServices.Designer.cs | 73 +++++++++++- BeautySalon/BeautySalon/FormServices.cs | 80 ++++++++++++- BeautySalon/BeautySalon/FormServices.resx | 50 ++++---- BeautySalon/BeautySalon/Program.cs | 14 +++ .../Implements/ServiceDatabase.cs | 13 ++ 11 files changed, 459 insertions(+), 80 deletions(-) diff --git a/BeautySalon/BeautySalon/FormMain.Designer.cs b/BeautySalon/BeautySalon/FormMain.Designer.cs index 9d6ba75..8209e50 100644 --- a/BeautySalon/BeautySalon/FormMain.Designer.cs +++ b/BeautySalon/BeautySalon/FormMain.Designer.cs @@ -74,18 +74,21 @@ добавитьToolStripMenuItem1.Name = "добавитьToolStripMenuItem1"; добавитьToolStripMenuItem1.Size = new Size(83, 24); добавить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"; посмотретьЧекиToolStripMenuItem.Size = new Size(143, 24); посмотретьЧекиToolStripMenuItem.Text = "Посмотреть чеки"; + посмотретьЧекиToolStripMenuItem.Click += посмотретьЧекиToolStripMenuItem_Click; // // FormMain // diff --git a/BeautySalon/BeautySalon/FormMain.cs b/BeautySalon/BeautySalon/FormMain.cs index 2911f96..9097fd8 100644 --- a/BeautySalon/BeautySalon/FormMain.cs +++ b/BeautySalon/BeautySalon/FormMain.cs @@ -20,9 +20,19 @@ namespace BeautySalon InitializeComponent(); } + + /// + /// это для услуг ес че + /// + /// + /// private void добавитьToolStripMenuItem_Click(object sender, EventArgs e) { - + var service = Program.ServiceProvider?.GetService(typeof(FormServices)); + if (service is FormServices form) + { + form.ShowDialog(); + } } private void добавитьСпециализациюToolStripMenuItem_Click(object sender, EventArgs e) @@ -42,5 +52,37 @@ namespace BeautySalon form.ShowDialog(); } } + + /// + /// эт клиенты + /// + /// + /// + private void добавитьToolStripMenuItem1_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormClients)); + if (service is FormClients form) + { + form.ShowDialog(); + } + } + + 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)); + if (service is FormCheques form) + { + form.ShowDialog(); + } + } } } diff --git a/BeautySalon/BeautySalon/FormMasters.cs b/BeautySalon/BeautySalon/FormMasters.cs index 2c9cdff..d433d70 100644 --- a/BeautySalon/BeautySalon/FormMasters.cs +++ b/BeautySalon/BeautySalon/FormMasters.cs @@ -1,15 +1,6 @@ using BeautySalonDBModels; using BeautySalonDBModels.Implements; using BeautySalonDBModels.Models; -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; namespace BeautySalon { diff --git a/BeautySalon/BeautySalon/FormService.Designer.cs b/BeautySalon/BeautySalon/FormService.Designer.cs index 6f6e30f..45e21ee 100644 --- a/BeautySalon/BeautySalon/FormService.Designer.cs +++ b/BeautySalon/BeautySalon/FormService.Designer.cs @@ -28,12 +28,116 @@ /// private void InitializeComponent() { - this.components = new System.ComponentModel.Container(); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "FormService"; + buttonCancel = new Button(); + buttonSave = new Button(); + labelSpecialisation = new Label(); + comboBoxSpecialisation = new ComboBox(); + FIO = new Label(); + textBoxName = new TextBox(); + numericUpDownPrice = new NumericUpDown(); + label = new Label(); + ((System.ComponentModel.ISupportInitialize)numericUpDownPrice).BeginInit(); + SuspendLayout(); + // + // buttonCancel + // + buttonCancel.Location = new Point(334, 224); + 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(26, 224); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(133, 44); + buttonSave.TabIndex = 10; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // labelSpecialisation + // + labelSpecialisation.AutoSize = true; + labelSpecialisation.Location = new Point(26, 83); + labelSpecialisation.Name = "labelSpecialisation"; + labelSpecialisation.Size = new Size(122, 20); + labelSpecialisation.TabIndex = 9; + labelSpecialisation.Text = "Специализация:"; + // + // comboBoxSpecialisation + // + comboBoxSpecialisation.FormattingEnabled = true; + comboBoxSpecialisation.Location = new Point(177, 80); + comboBoxSpecialisation.Name = "comboBoxSpecialisation"; + comboBoxSpecialisation.Size = new Size(290, 28); + comboBoxSpecialisation.TabIndex = 8; + // + // FIO + // + FIO.AutoSize = true; + FIO.Location = new Point(26, 28); + FIO.Name = "FIO"; + FIO.Size = new Size(57, 20); + FIO.TabIndex = 7; + FIO.Text = "Услуга:"; + // + // textBoxName + // + textBoxName.Location = new Point(177, 21); + textBoxName.Name = "textBoxName"; + textBoxName.Size = new Size(290, 27); + textBoxName.TabIndex = 6; + // + // numericUpDownPrice + // + numericUpDownPrice.Location = new Point(177, 140); + numericUpDownPrice.Name = "numericUpDownPrice"; + numericUpDownPrice.Size = new Size(290, 27); + numericUpDownPrice.TabIndex = 12; + // + // label + // + label.AutoSize = true; + label.Location = new Point(26, 147); + label.Name = "label"; + label.Size = new Size(45, 20); + label.TabIndex = 13; + label.Text = "Цена"; + // + // FormService + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(537, 304); + Controls.Add(label); + Controls.Add(numericUpDownPrice); + Controls.Add(buttonCancel); + Controls.Add(buttonSave); + Controls.Add(labelSpecialisation); + Controls.Add(comboBoxSpecialisation); + Controls.Add(FIO); + Controls.Add(textBoxName); + Name = "FormService"; + Text = "FormService"; + Load += FormService_Load; + ((System.ComponentModel.ISupportInitialize)numericUpDownPrice).EndInit(); + ResumeLayout(false); + PerformLayout(); } #endregion + + private Button buttonCancel; + private Button buttonSave; + private Label labelSpecialisation; + private ComboBox comboBoxSpecialisation; + private Label FIO; + private TextBox textBoxName; + private NumericUpDown numericUpDownPrice; + private Label label; } } \ No newline at end of file diff --git a/BeautySalon/BeautySalon/FormService.cs b/BeautySalon/BeautySalon/FormService.cs index 2598858..6729dc8 100644 --- a/BeautySalon/BeautySalon/FormService.cs +++ b/BeautySalon/BeautySalon/FormService.cs @@ -1,20 +1,91 @@ -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; +using BeautySalonDBModels.Models; namespace BeautySalon { public partial class FormService : Form { - public FormService() + private int? _id; + public int Id { + set { _id = value; } + } + + private readonly AbstractWorkWithStorage specialisationStorage; + private readonly AbstractWorkWithStorage serviceStorage; + private readonly List specialisations; + + public FormService(AbstractWorkWithStorage serviceStorage, AbstractWorkWithStorage specialisationStorage) + { + this.serviceStorage = serviceStorage; + this.specialisationStorage = specialisationStorage; InitializeComponent(); + + specialisations = specialisationStorage.GetObjects(); + foreach (Specialisation specialisation in specialisations) + { + comboBoxSpecialisation.Items.Add(specialisation).ToString(); + } + } + + private void buttonSave_Click(object sender, EventArgs e) + { + try + { + if (_id != null) + { + var newService = new Service + { + ServiceId = _id ?? 0, + SpecialisationId = (comboBoxSpecialisation.SelectedItem as Service)!.ServiceId, + Price = (int)numericUpDownPrice.Value + }; + serviceStorage.Update(newService); + } + else + { + var newService = new Service + { + SpecialisationId = (comboBoxSpecialisation.SelectedItem as Service)!.ServiceId, + Price = (int)numericUpDownPrice.Value + }; + serviceStorage.Add(newService); + } + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception) + { + + throw; + } + } + + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; Close(); + } + + private void FormService_Load(object sender, EventArgs e) + { + if(_id != null) + { + try + { + var serviceObject = serviceStorage.GetObject(_id.Value); + if (serviceObject != null) + { + comboBoxSpecialisation.SelectedItem = serviceObject; + textBoxName.Text = serviceObject.ServiceName; + numericUpDownPrice.Value = (decimal)serviceObject.Price; + } + } + catch (Exception) + { + + throw; + } + } } } } diff --git a/BeautySalon/BeautySalon/FormService.resx b/BeautySalon/BeautySalon/FormService.resx index 1af7de1..af32865 100644 --- a/BeautySalon/BeautySalon/FormService.resx +++ b/BeautySalon/BeautySalon/FormService.resx @@ -1,17 +1,17 @@  - diff --git a/BeautySalon/BeautySalon/FormServices.Designer.cs b/BeautySalon/BeautySalon/FormServices.Designer.cs index 9aaa8c4..e95385a 100644 --- a/BeautySalon/BeautySalon/FormServices.Designer.cs +++ b/BeautySalon/BeautySalon/FormServices.Designer.cs @@ -28,12 +28,77 @@ /// private void InitializeComponent() { - this.components = new System.ComponentModel.Container(); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(800, 450); - this.Text = "FormServices"; + dataGridView = new DataGridView(); + buttonDelete = new Button(); + buttonUpdate = new Button(); + buttonCreate = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // dataGridView + // + dataGridView.BackgroundColor = SystemColors.ActiveCaption; + 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(493, 450); + dataGridView.TabIndex = 0; + // + // buttonDelete + // + buttonDelete.Location = new Point(553, 365); + buttonDelete.Name = "buttonDelete"; + buttonDelete.Size = new Size(147, 56); + buttonDelete.TabIndex = 9; + buttonDelete.Text = "Уничтожить..."; + buttonDelete.UseVisualStyleBackColor = true; + buttonDelete.Click += buttonDelete_Click; + // + // buttonUpdate + // + buttonUpdate.Location = new Point(553, 195); + buttonUpdate.Name = "buttonUpdate"; + buttonUpdate.Size = new Size(147, 56); + buttonUpdate.TabIndex = 8; + buttonUpdate.Text = "Корректровать"; + buttonUpdate.UseVisualStyleBackColor = true; + buttonUpdate.Click += buttonUpdate_Click; + // + // buttonCreate + // + buttonCreate.Location = new Point(553, 34); + buttonCreate.Name = "buttonCreate"; + buttonCreate.Size = new Size(147, 56); + buttonCreate.TabIndex = 7; + buttonCreate.Text = "Добавить"; + buttonCreate.UseVisualStyleBackColor = true; + buttonCreate.Click += buttonCreate_Click; + // + // FormServices + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(752, 450); + Controls.Add(buttonDelete); + Controls.Add(buttonUpdate); + Controls.Add(buttonCreate); + Controls.Add(dataGridView); + Name = "FormServices"; + Text = "Услуги"; + Load += FormServices_Load; + ((System.ComponentModel.ISupportInitialize)dataGridView).EndInit(); + ResumeLayout(false); } #endregion + + private DataGridView dataGridView; + private Button buttonDelete; + private Button buttonUpdate; + private Button buttonCreate; } } \ No newline at end of file diff --git a/BeautySalon/BeautySalon/FormServices.cs b/BeautySalon/BeautySalon/FormServices.cs index cb21187..92850eb 100644 --- a/BeautySalon/BeautySalon/FormServices.cs +++ b/BeautySalon/BeautySalon/FormServices.cs @@ -1,4 +1,6 @@ -using System; +using BeautySalonDBModels.Models; +using BeautySalonDBModels; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; @@ -7,14 +9,88 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using BeautySalonDBModels.Implements; namespace BeautySalon { public partial class FormServices : Form { - public FormServices() + private int? _id; + public int Id { + set { _id = value; } + } + + private readonly AbstractWorkWithStorage serviceStorage; + private readonly AbstractWorkWithStorage specialisationStorage; + public FormServices(AbstractWorkWithStorage serviceStorage, + AbstractWorkWithStorage specialisationStorage) + { + this.serviceStorage = serviceStorage; + this.specialisationStorage = specialisationStorage; InitializeComponent(); } + + private void LoadData() + { + List services = serviceStorage.GetObjects(); + ServiceDatabase mdb = new ServiceDatabase(); + + dataGridView.Rows.Clear(); + + if (dataGridView.ColumnCount == 0) + { + dataGridView.Columns.Add("ServiceName", "Название"); + dataGridView.Columns.Add("Specialisation", "Специализация"); + dataGridView.Columns.Add("Price", "Цена"); + } + + foreach (Service service in services) + { + string specialisationName = mdb.GetNameSpecialisation(service); + dataGridView.Rows.Add(service.ServiceName, specialisationName, service.Price); + } + } + + private void buttonCreate_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormService)); + if (service is FormService form) + { + if (form.ShowDialog() == DialogResult.OK) + { + LoadData(); + } + } + } + + private void buttonUpdate_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormService)); + if (service is FormService form) + { + if (form.ShowDialog() == DialogResult.OK) + { + int rowIndex = dataGridView.CurrentCell.RowIndex; + form.Id = (int)dataGridView.Rows[rowIndex].Cells["ServiceId"].Value; + LoadData(); + } + } + } + + private void buttonDelete_Click(object sender, EventArgs e) + { + if(dataGridView.SelectedRows.Count == 1) + { + int rowIndex = dataGridView.CurrentCell.RowIndex; + serviceStorage.Remove(rowIndex); + LoadData(); + } + } + + private void FormServices_Load(object sender, EventArgs e) + { + LoadData(); + } } } diff --git a/BeautySalon/BeautySalon/FormServices.resx b/BeautySalon/BeautySalon/FormServices.resx index 1af7de1..af32865 100644 --- a/BeautySalon/BeautySalon/FormServices.resx +++ b/BeautySalon/BeautySalon/FormServices.resx @@ -1,17 +1,17 @@  - diff --git a/BeautySalon/BeautySalon/Program.cs b/BeautySalon/BeautySalon/Program.cs index c1c9682..61232f4 100644 --- a/BeautySalon/BeautySalon/Program.cs +++ b/BeautySalon/BeautySalon/Program.cs @@ -49,10 +49,24 @@ namespace BeautySalon services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); + services.AddTransient(); services.AddTransient(); + + services.AddTransient(); + services.AddTransient(); + + services.AddTransient(); + services.AddTransient(); + + services.AddTransient(); + services.AddTransient(); + + services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file diff --git a/BeautySalon/BeautySalonDBModels/Implements/ServiceDatabase.cs b/BeautySalon/BeautySalonDBModels/Implements/ServiceDatabase.cs index 1e99e80..abc2f48 100644 --- a/BeautySalon/BeautySalonDBModels/Implements/ServiceDatabase.cs +++ b/BeautySalon/BeautySalonDBModels/Implements/ServiceDatabase.cs @@ -85,5 +85,18 @@ namespace BeautySalonDBModels.Implements cmd.Parameters.AddWithValue("@id", service.ServiceId); cmd.ExecuteNonQuery(); } + + public string GetNameSpecialisation(Service service) + { + SpecialisationDatabase db = new SpecialisationDatabase(); + int specId = service.SpecialisationId; + List specialisations = db.GetObjects(); + + foreach (Specialisation specialisation in specialisations) + { + if (specialisation.SpecialisationId == specId) return specialisation.Name.ToString(); + } + return string.Empty; + } } }