diff --git a/BeautySalon/BeautySalon/FormClient.Designer.cs b/BeautySalon/BeautySalon/FormClient.Designer.cs index f53ac2e..8438e1d 100644 --- a/BeautySalon/BeautySalon/FormClient.Designer.cs +++ b/BeautySalon/BeautySalon/FormClient.Designer.cs @@ -28,12 +28,93 @@ /// 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 = "FormClient"; + labelName = new Label(); + buttonCancel = new Button(); + textBoxFIO = new TextBox(); + buttonSave = new Button(); + numericUpDownAge = new NumericUpDown(); + label = new Label(); + ((System.ComponentModel.ISupportInitialize)numericUpDownAge).BeginInit(); + SuspendLayout(); + // + // labelName + // + labelName.AutoSize = true; + labelName.Location = new Point(23, 62); + labelName.Name = "labelName"; + labelName.Size = new Size(42, 20); + labelName.TabIndex = 7; + labelName.Text = "ФИО"; + // + // buttonCancel + // + buttonCancel.Location = new Point(164, 202); + buttonCancel.Name = "buttonCancel"; + buttonCancel.Size = new Size(133, 44); + buttonCancel.TabIndex = 6; + buttonCancel.Text = "Отмена"; + buttonCancel.UseVisualStyleBackColor = true; + buttonCancel.Click += buttonCancel_Click; + // + // textBoxFIO + // + textBoxFIO.Location = new Point(23, 23); + textBoxFIO.Name = "textBoxFIO"; + textBoxFIO.Size = new Size(274, 27); + textBoxFIO.TabIndex = 5; + // + // buttonSave + // + buttonSave.Location = new Point(23, 202); + buttonSave.Name = "buttonSave"; + buttonSave.Size = new Size(133, 44); + buttonSave.TabIndex = 4; + buttonSave.Text = "Сохранить"; + buttonSave.UseVisualStyleBackColor = true; + buttonSave.Click += buttonSave_Click; + // + // numericUpDownAge + // + numericUpDownAge.Location = new Point(23, 108); + numericUpDownAge.Name = "numericUpDownAge"; + numericUpDownAge.Size = new Size(274, 27); + numericUpDownAge.TabIndex = 8; + // + // label + // + label.AutoSize = true; + label.Location = new Point(23, 156); + label.Name = "label"; + label.Size = new Size(64, 20); + label.TabIndex = 9; + label.Text = "Возраст"; + // + // FormClient + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(338, 282); + Controls.Add(label); + Controls.Add(numericUpDownAge); + Controls.Add(labelName); + Controls.Add(buttonCancel); + Controls.Add(textBoxFIO); + Controls.Add(buttonSave); + Name = "FormClient"; + Text = "Клиент"; + Load += FormClient_Load; + ((System.ComponentModel.ISupportInitialize)numericUpDownAge).EndInit(); + ResumeLayout(false); + PerformLayout(); } #endregion + + private Label labelName; + private Button buttonCancel; + private TextBox textBoxFIO; + private Button buttonSave; + private NumericUpDown numericUpDownAge; + private Label label; } } \ No newline at end of file diff --git a/BeautySalon/BeautySalon/FormClient.cs b/BeautySalon/BeautySalon/FormClient.cs index dcad860..04578ca 100644 --- a/BeautySalon/BeautySalon/FormClient.cs +++ b/BeautySalon/BeautySalon/FormClient.cs @@ -1,20 +1,83 @@ -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 FormClient : Form { - public FormClient() + + private int? _id; + public int Id { + set { _id = value; } + } + + private readonly AbstractWorkWithStorage clientStorage; + + public FormClient(AbstractWorkWithStorage clientStorage) + { + this.clientStorage = clientStorage; InitializeComponent(); } + + private void buttonSave_Click(object sender, EventArgs e) + { + try + { + if (_id != null) + { + var newClient = new Client + { + ClientId = _id ?? 0, + FIO = textBoxFIO.Text, + Age = (int)numericUpDownAge.Value, + }; + clientStorage.Update(newClient); + } + else + { + var newClient = new Client + { + FIO = textBoxFIO.Text, + Age = (int)numericUpDownAge.Value, + }; + clientStorage.Add(newClient); + } + DialogResult = DialogResult.OK; + Close(); + } + catch (Exception) + { + + throw; + } + + } + + private void buttonCancel_Click(object sender, EventArgs e) + { + DialogResult = DialogResult.Cancel; Close(); + } + + private void FormClient_Load(object sender, EventArgs e) + { + if (_id.HasValue) + { + try + { + var client = clientStorage.GetObject(_id.Value); + if (client != null) + { + textBoxFIO.Text = client.FIO.ToString(); + numericUpDownAge.Value = (decimal)client.Age; + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, + MessageBoxIcon.Error); + } + } + } } } diff --git a/BeautySalon/BeautySalon/FormClient.resx b/BeautySalon/BeautySalon/FormClient.resx index 1af7de1..af32865 100644 --- a/BeautySalon/BeautySalon/FormClient.resx +++ b/BeautySalon/BeautySalon/FormClient.resx @@ -1,17 +1,17 @@  - diff --git a/BeautySalon/BeautySalon/FormClients.Designer.cs b/BeautySalon/BeautySalon/FormClients.Designer.cs index 160d69a..0e5688e 100644 --- a/BeautySalon/BeautySalon/FormClients.Designer.cs +++ b/BeautySalon/BeautySalon/FormClients.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 = "FormClients"; + buttonDelete = new Button(); + buttonUpdate = new Button(); + buttonCreate = new Button(); + dataGridView = new DataGridView(); + ((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit(); + SuspendLayout(); + // + // buttonDelete + // + buttonDelete.Location = new Point(480, 356); + buttonDelete.Name = "buttonDelete"; + buttonDelete.Size = new Size(147, 56); + buttonDelete.TabIndex = 7; + buttonDelete.Text = "Уничтожить..."; + buttonDelete.UseVisualStyleBackColor = true; + buttonDelete.Click += buttonDelete_Click; + // + // buttonUpdate + // + buttonUpdate.Location = new Point(480, 186); + buttonUpdate.Name = "buttonUpdate"; + buttonUpdate.Size = new Size(147, 56); + buttonUpdate.TabIndex = 6; + buttonUpdate.Text = "Корректровать"; + buttonUpdate.UseVisualStyleBackColor = true; + buttonUpdate.Click += buttonUpdate_Click; + // + // buttonCreate + // + buttonCreate.Location = new Point(480, 25); + buttonCreate.Name = "buttonCreate"; + buttonCreate.Size = new Size(147, 56); + buttonCreate.TabIndex = 5; + buttonCreate.Text = "Добавить"; + buttonCreate.UseVisualStyleBackColor = true; + buttonCreate.Click += buttonCreate_Click; + // + // dataGridView + // + dataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; + 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(417, 450); + dataGridView.TabIndex = 4; + // + // FormClients + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(683, 450); + Controls.Add(buttonDelete); + Controls.Add(buttonUpdate); + Controls.Add(buttonCreate); + Controls.Add(dataGridView); + Name = "FormClients"; + Text = "Клиенты"; + Load += FormClients_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/FormClients.cs b/BeautySalon/BeautySalon/FormClients.cs index a77935a..3053bb2 100644 --- a/BeautySalon/BeautySalon/FormClients.cs +++ b/BeautySalon/BeautySalon/FormClients.cs @@ -1,20 +1,79 @@ -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 FormClients : Form { - public FormClients() + + private int? _id; + public int Id { + set { _id = value; } + } + + private readonly AbstractWorkWithStorage clientStorage; + + public FormClients(AbstractWorkWithStorage clientStorage) + { + this.clientStorage = clientStorage; InitializeComponent(); } + + private void LoadData() + { + var list = clientStorage.GetObjects(); + if (list != null) + { + dataGridView.DataSource = list; + } + } + + private void FormClients_Load(object sender, EventArgs e) + { + LoadData(); + } + + private void buttonCreate_Click(object sender, EventArgs e) + { + var service = Program.ServiceProvider?.GetService(typeof(FormClient)); + if (service is FormClient 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(FormClient)); + if (service is FormClient form) + { + + int index = dataGridView.CurrentCell.RowIndex; + form.Id = (int)dataGridView.Rows[index].Cells["ClientId"].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["ClientId"].Value); + clientStorage.Remove(id); + LoadData(); + } + } } } + diff --git a/BeautySalon/BeautySalon/FormClients.resx b/BeautySalon/BeautySalon/FormClients.resx index 1af7de1..af32865 100644 --- a/BeautySalon/BeautySalon/FormClients.resx +++ b/BeautySalon/BeautySalon/FormClients.resx @@ -1,17 +1,17 @@  - diff --git a/BeautySalon/BeautySalon/FormSpecialisation.cs b/BeautySalon/BeautySalon/FormSpecialisation.cs index 44d0e8e..21fb294 100644 --- a/BeautySalon/BeautySalon/FormSpecialisation.cs +++ b/BeautySalon/BeautySalon/FormSpecialisation.cs @@ -1,14 +1,5 @@ using BeautySalonDBModels; 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 {