доделала формы рецептов (нужно все еще не забыть всем формам прописать проверки данных)

This commit is contained in:
Елена Бакальская 2024-05-08 12:37:12 +04:00
parent 0c59a3f9c0
commit 15d644a6bc
6 changed files with 427 additions and 78 deletions

View File

@ -28,12 +28,116 @@
/// </summary>
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;
}
}

View File

@ -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<Service> services;
private List<Master> masters;
private readonly AbstractWorkWithStorage<Reception> receptionStorage;
private readonly AbstractWorkWithStorage<Service> serviceStorage;
private readonly AbstractWorkWithStorage<Master> masterStorage;
private int? _id;
public int Id
{
set { _id = value; }
}
public FormReception(AbstractWorkWithStorage<Reception> receptionStorage,
AbstractWorkWithStorage<Service> serviceStorage,
AbstractWorkWithStorage<Master> 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<Master> mss = sdb.GetFilteredListByService(serviceId);
foreach (Master master in mss)
{
comboBoxMaster.Items.Add(master).ToString();
}
}
}
}
}

View File

@ -28,12 +28,78 @@
/// </summary>
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;
}
}

View File

@ -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<Reception> receptionStorage;
private readonly AbstractWorkWithStorage<Service> serviceStorage;
private readonly AbstractWorkWithStorage<Master> masterStorage;
public FormReceptions(AbstractWorkWithStorage<Reception> receptionStorage,
AbstractWorkWithStorage<Service> serviceStorage,
AbstractWorkWithStorage<Master> masterStorage)
{
this.receptionStorage = receptionStorage;
this.serviceStorage = serviceStorage;
this.masterStorage = masterStorage;
InitializeComponent();
}
private void LoadData()
{
List<Reception> 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();
}
}
}