добавила клиентов форму
This commit is contained in:
parent
2026569f00
commit
2a009156e1
89
BeautySalon/BeautySalon/FormClient.Designer.cs
generated
89
BeautySalon/BeautySalon/FormClient.Designer.cs
generated
@ -28,12 +28,93 @@
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
this.components = new System.ComponentModel.Container();
|
labelName = new Label();
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
buttonCancel = new Button();
|
||||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
textBoxFIO = new TextBox();
|
||||||
this.Text = "FormClient";
|
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
|
#endregion
|
||||||
|
|
||||||
|
private Label labelName;
|
||||||
|
private Button buttonCancel;
|
||||||
|
private TextBox textBoxFIO;
|
||||||
|
private Button buttonSave;
|
||||||
|
private NumericUpDown numericUpDownAge;
|
||||||
|
private Label label;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,20 +1,83 @@
|
|||||||
using System;
|
using BeautySalonDBModels;
|
||||||
using System.Collections.Generic;
|
using BeautySalonDBModels.Models;
|
||||||
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
|
namespace BeautySalon
|
||||||
{
|
{
|
||||||
public partial class FormClient : Form
|
public partial class FormClient : Form
|
||||||
{
|
{
|
||||||
public FormClient()
|
|
||||||
|
private int? _id;
|
||||||
|
public int Id
|
||||||
{
|
{
|
||||||
|
set { _id = value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
private readonly AbstractWorkWithStorage<Client> clientStorage;
|
||||||
|
|
||||||
|
public FormClient(AbstractWorkWithStorage<Client> clientStorage)
|
||||||
|
{
|
||||||
|
this.clientStorage = clientStorage;
|
||||||
InitializeComponent();
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
74
BeautySalon/BeautySalon/FormClients.Designer.cs
generated
74
BeautySalon/BeautySalon/FormClients.Designer.cs
generated
@ -28,12 +28,78 @@
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
this.components = new System.ComponentModel.Container();
|
buttonDelete = new Button();
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
buttonUpdate = new Button();
|
||||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
buttonCreate = new Button();
|
||||||
this.Text = "FormClients";
|
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
|
#endregion
|
||||||
|
|
||||||
|
private Button buttonDelete;
|
||||||
|
private Button buttonUpdate;
|
||||||
|
private Button buttonCreate;
|
||||||
|
private DataGridView dataGridView;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,20 +1,79 @@
|
|||||||
using System;
|
using BeautySalonDBModels;
|
||||||
using System.Collections.Generic;
|
using BeautySalonDBModels.Models;
|
||||||
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
|
namespace BeautySalon
|
||||||
{
|
{
|
||||||
public partial class FormClients : Form
|
public partial class FormClients : Form
|
||||||
{
|
{
|
||||||
public FormClients()
|
|
||||||
|
private int? _id;
|
||||||
|
public int Id
|
||||||
{
|
{
|
||||||
|
set { _id = value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
private readonly AbstractWorkWithStorage<Client> clientStorage;
|
||||||
|
|
||||||
|
public FormClients(AbstractWorkWithStorage<Client> clientStorage)
|
||||||
|
{
|
||||||
|
this.clientStorage = clientStorage;
|
||||||
InitializeComponent();
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,14 +1,5 @@
|
|||||||
using BeautySalonDBModels;
|
using BeautySalonDBModels;
|
||||||
using BeautySalonDBModels.Models;
|
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
|
namespace BeautySalon
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user