152 lines
5.9 KiB
C#
152 lines
5.9 KiB
C#
using HotelAbstractions.Logic;
|
||
using HotelAbstractions.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 HotelView
|
||
{
|
||
public partial class FormServiceCheck : Form
|
||
{
|
||
private readonly IServiceCheckLogic _serviceCheckLogic;
|
||
private readonly IReservationLogic _reservationLogic;
|
||
private readonly IServiceLogic _serviceLogic;
|
||
public FormServiceCheck(IServiceCheckLogic serviceCheckLogic, IReservationLogic reservationLogic, IServiceLogic serviceLogic)
|
||
{
|
||
InitializeComponent();
|
||
_serviceCheckLogic = serviceCheckLogic;
|
||
_reservationLogic = reservationLogic;
|
||
_serviceLogic = serviceLogic;
|
||
}
|
||
|
||
private void FormServiceCheck_Load(object sender, EventArgs e)
|
||
{
|
||
LoadData();
|
||
}
|
||
|
||
private void ButtonCreate_Click(object sender, EventArgs e)
|
||
{
|
||
ServiceCheck newServiceCheck = new()
|
||
{
|
||
ReservationId = ((Reservation?)comboBoxReservation.SelectedItem)?.Id ?? 0,
|
||
ServiceId = ((Service?)comboBoxService.SelectedItem)?.Id ?? 0,
|
||
Count = (int)numericUpDownCount.Value,
|
||
DateTime = dateTimePicker.Value,
|
||
};
|
||
|
||
_serviceCheckLogic.Create(newServiceCheck);
|
||
|
||
LoadData();
|
||
}
|
||
|
||
private void LoadData()
|
||
{
|
||
var serviceChecks = _serviceCheckLogic.GetAll();
|
||
|
||
dataGridView.Rows.Clear();
|
||
|
||
if (dataGridView.ColumnCount == 0)
|
||
{
|
||
dataGridView.Columns.Add("Id", "ID");
|
||
dataGridView.Columns.Add("ReservationId", "ReservationId");
|
||
dataGridView.Columns["ReservationId"].Visible = false;
|
||
dataGridView.Columns.Add("Reservation", "Бронирование");
|
||
dataGridView.Columns.Add("ServiceId", "ServiceId");
|
||
dataGridView.Columns["ServiceId"].Visible = false;
|
||
dataGridView.Columns.Add("Service", "Услуга");
|
||
dataGridView.Columns.Add("Count", "Количество");
|
||
dataGridView.Columns.Add("DateTime", "Дата время");
|
||
|
||
}
|
||
|
||
dataGridView.Columns["Id"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||
dataGridView.Columns["Reservation"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||
dataGridView.Columns["Service"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||
dataGridView.Columns["Count"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||
dataGridView.Columns["DateTime"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||
|
||
comboBoxReservation.DataSource = _reservationLogic.GetAll();
|
||
comboBoxReservation.DisplayMember = "Reservation";
|
||
comboBoxReservation.ValueMember = "Id";
|
||
|
||
comboBoxService.DataSource = _serviceLogic.GetAll();
|
||
comboBoxService.DisplayMember = "Service";
|
||
comboBoxService.ValueMember = "Name";
|
||
|
||
foreach (var serviceCheck in serviceChecks)
|
||
{
|
||
dataGridView.Rows.Add(serviceCheck.Id,
|
||
serviceCheck.ReservationId, _reservationLogic.Get(serviceCheck.ReservationId)?.Id,
|
||
serviceCheck.ServiceId, _serviceLogic.Get(serviceCheck.ServiceId)?.Name,
|
||
serviceCheck.Count,
|
||
serviceCheck.DateTime);
|
||
}
|
||
}
|
||
|
||
private void ButtonUpdate_Click(object sender, EventArgs e)
|
||
{
|
||
if (dataGridView.SelectedRows.Count > 0)
|
||
{
|
||
DataGridViewRow selectedRow = dataGridView.SelectedRows[0];
|
||
int serviceCheckId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
||
|
||
ServiceCheck updatedServiceCheck = new()
|
||
{
|
||
Id = serviceCheckId,
|
||
ReservationId = ((Reservation?)comboBoxReservation.SelectedItem)?.Id ?? 0,
|
||
ServiceId = ((Service?)comboBoxService.SelectedItem)?.Id ?? 0,
|
||
Count = (int)numericUpDownCount.Value,
|
||
DateTime = dateTimePicker.Value,
|
||
};
|
||
|
||
_serviceCheckLogic.Update(updatedServiceCheck);
|
||
|
||
LoadData();
|
||
}
|
||
else
|
||
{
|
||
MessageBox.Show("Пожалуйста, выберите статью, информацию о которой необходимо обновить");
|
||
}
|
||
}
|
||
|
||
private void ButtonDelete_Click(object sender, EventArgs e)
|
||
{
|
||
if (dataGridView.SelectedRows.Count > 0)
|
||
{
|
||
DataGridViewRow selectedRow = dataGridView.SelectedRows[0];
|
||
int serviceCheckId = Convert.ToInt32(selectedRow.Cells["Id"].Value);
|
||
|
||
_serviceCheckLogic.Delete(serviceCheckId);
|
||
|
||
LoadData();
|
||
}
|
||
else
|
||
{
|
||
MessageBox.Show("Пожалуйста, выберите статью, информацию о которой необходимо удалить");
|
||
}
|
||
}
|
||
|
||
private void DataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
|
||
{
|
||
if (e.RowIndex >= 0)
|
||
{
|
||
DataGridViewRow row = dataGridView.Rows[e.RowIndex];
|
||
comboBoxReservation.SelectedValue = row.Cells["Reservation"].Value ?? new Reservation { Id = 0 };
|
||
comboBoxService.SelectedValue = row.Cells["Service"].Value ?? new Service { Name = "Неизвестно" };
|
||
numericUpDownCount.Text = row.Cells["Count"].Value.ToString();
|
||
dateTimePicker.Text = row.Cells["DateTime"].Value.ToString();
|
||
}
|
||
}
|
||
public FormServiceCheck()
|
||
{
|
||
InitializeComponent();
|
||
}
|
||
}
|
||
}
|