From 15d644a6bc67163d6756e6117a122bc560485eae 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 12:37:12 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB?= =?UTF-8?q?=D0=B0=20=D1=84=D0=BE=D1=80=D0=BC=D1=8B=20=D1=80=D0=B5=D1=86?= =?UTF-8?q?=D0=B5=D0=BF=D1=82=D0=BE=D0=B2=20(=D0=BD=D1=83=D0=B6=D0=BD?= =?UTF-8?q?=D0=BE=20=D0=B2=D1=81=D0=B5=20=D0=B5=D1=89=D0=B5=20=D0=BD=D0=B5?= =?UTF-8?q?=20=D0=B7=D0=B0=D0=B1=D1=8B=D1=82=D1=8C=20=D0=B2=D1=81=D0=B5?= =?UTF-8?q?=D0=BC=20=D1=84=D0=BE=D1=80=D0=BC=D0=B0=D0=BC=20=D0=BF=D1=80?= =?UTF-8?q?=D0=BE=D0=BF=D0=B8=D1=81=D0=B0=D1=82=D1=8C=20=D0=BF=D1=80=D0=BE?= =?UTF-8?q?=D0=B2=D0=B5=D1=80=D0=BA=D0=B8=20=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B?= =?UTF-8?q?=D1=85)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BeautySalon/FormReception.Designer.cs | 112 +++++++++++++++- BeautySalon/BeautySalon/FormReception.cs | 121 ++++++++++++++++-- BeautySalon/BeautySalon/FormReception.resx | 50 ++++---- .../BeautySalon/FormReceptions.Designer.cs | 74 ++++++++++- BeautySalon/BeautySalon/FormReceptions.cs | 98 ++++++++++++-- BeautySalon/BeautySalon/FormReceptions.resx | 50 ++++---- 6 files changed, 427 insertions(+), 78 deletions(-) diff --git a/BeautySalon/BeautySalon/FormReception.Designer.cs b/BeautySalon/BeautySalon/FormReception.Designer.cs index b9c7835..82fdb0d 100644 --- a/BeautySalon/BeautySalon/FormReception.Designer.cs +++ b/BeautySalon/BeautySalon/FormReception.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 = "FormReception"; + 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 index 2bc9d7e..b034172 100644 --- a/BeautySalon/BeautySalon/FormReception.cs +++ b/BeautySalon/BeautySalon/FormReception.cs @@ -1,20 +1,121 @@ -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.Implements; +using BeautySalonDBModels.Models; namespace BeautySalon { public partial class FormReception : Form { - public FormReception() + 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 index 1af7de1..af32865 100644 --- a/BeautySalon/BeautySalon/FormReception.resx +++ b/BeautySalon/BeautySalon/FormReception.resx @@ -1,17 +1,17 @@  - diff --git a/BeautySalon/BeautySalon/FormReceptions.Designer.cs b/BeautySalon/BeautySalon/FormReceptions.Designer.cs index 057f069..ff3c7db 100644 --- a/BeautySalon/BeautySalon/FormReceptions.Designer.cs +++ b/BeautySalon/BeautySalon/FormReceptions.Designer.cs @@ -28,12 +28,78 @@ /// 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 = "FormReceptions"; + 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 index f0df1bb..7d4dee2 100644 --- a/BeautySalon/BeautySalon/FormReceptions.cs +++ b/BeautySalon/BeautySalon/FormReceptions.cs @@ -1,20 +1,98 @@ -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.Models; +using BeautySalonDBModels; +using BeautySalonDBModels.Implements; namespace BeautySalon { public partial class FormReceptions : Form { - public FormReceptions() + + 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 index 1af7de1..af32865 100644 --- a/BeautySalon/BeautySalon/FormReceptions.resx +++ b/BeautySalon/BeautySalon/FormReceptions.resx @@ -1,17 +1,17 @@  -