Рефакторинг
This commit is contained in:
parent
31367a7ba2
commit
6989711277
@ -50,47 +50,49 @@ public partial class FormAppointment : Form
|
|||||||
|
|
||||||
dateTimePickerEnd.ValueChanged += DateTimePickerEnd_ValueChanged;
|
dateTimePickerEnd.ValueChanged += DateTimePickerEnd_ValueChanged;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
private void DateTimePickerEnd_ValueChanged(object sender, EventArgs e)
|
||||||
private void DateTimePickerEnd_ValueChanged(object sender, EventArgs e)
|
{
|
||||||
|
if (dateTimePickerEnd.CustomFormat == "В процессе")
|
||||||
{
|
{
|
||||||
if (dateTimePickerEnd.CustomFormat == "В процессе")
|
dateTimePickerEnd.CustomFormat = "dd.MM.yyyy HH:mm";
|
||||||
{
|
|
||||||
dateTimePickerEnd.CustomFormat = "dd.MM.yyyy HH:mm";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private void ButtonAdd_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
if (comboBoxEmployee.SelectedIndex < 0 || comboBoxOrder.SelectedIndex < 0)
|
|
||||||
{
|
|
||||||
throw new Exception("Имеются незаполненные поля");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_appointmentId.HasValue)
|
|
||||||
{
|
|
||||||
_appointmentRepository.UpdateAppointment(CreateAppointment(_appointmentId.Value));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_appointmentRepository.CreateAppointment(CreateAppointment(0));
|
|
||||||
}
|
|
||||||
Close();
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
MessageBox.Show(ex.Message, "Ошибка при сохранении",
|
|
||||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private void ButtonCancel_Click(object sender, EventArgs e) => Close();
|
|
||||||
private Appointment CreateAppointment(int id)
|
|
||||||
{
|
|
||||||
DateTime? endDate = dateTimePickerEnd.CustomFormat == "В процессе" ? (DateTime?)null : dateTimePickerEnd.Value;
|
|
||||||
|
|
||||||
return Appointment.CreateOperation(id, (int)comboBoxOrder.SelectedValue!, (int)comboBoxEmployee.SelectedValue!, Convert.ToDateTime(dateTimePickerStart.Value),
|
|
||||||
endDate);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private void ButtonAdd_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (comboBoxEmployee.SelectedIndex < 0 || comboBoxOrder.SelectedIndex < 0)
|
||||||
|
{
|
||||||
|
throw new Exception("Имеются незаполненные поля");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_appointmentId.HasValue)
|
||||||
|
{
|
||||||
|
_appointmentRepository.UpdateAppointment(CreateAppointment(_appointmentId.Value));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_appointmentRepository.CreateAppointment(CreateAppointment(0));
|
||||||
|
}
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка при сохранении",
|
||||||
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonCancel_Click(object sender, EventArgs e) => Close();
|
||||||
|
|
||||||
|
private Appointment CreateAppointment(int id)
|
||||||
|
{
|
||||||
|
DateTime? endDate = dateTimePickerEnd.CustomFormat == "В процессе" ? (DateTime?)null : dateTimePickerEnd.Value;
|
||||||
|
|
||||||
|
return Appointment.CreateOperation(id, (int)comboBoxOrder.SelectedValue!, (int)comboBoxEmployee.SelectedValue!, Convert.ToDateTime(dateTimePickerStart.Value),
|
||||||
|
endDate);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,7 +80,6 @@
|
|||||||
buttonRemove.Size = new Size(86, 101);
|
buttonRemove.Size = new Size(86, 101);
|
||||||
buttonRemove.TabIndex = 3;
|
buttonRemove.TabIndex = 3;
|
||||||
buttonRemove.UseVisualStyleBackColor = true;
|
buttonRemove.UseVisualStyleBackColor = true;
|
||||||
buttonRemove.Click += buttonRemove_Click;
|
|
||||||
//
|
//
|
||||||
// buttonUpdate
|
// buttonUpdate
|
||||||
//
|
//
|
||||||
|
@ -22,34 +22,33 @@ internal static class Program
|
|||||||
Application.Run(CreateContainer().Resolve<FormItCompany>());
|
Application.Run(CreateContainer().Resolve<FormItCompany>());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
private static IUnityContainer CreateContainer()
|
||||||
|
{
|
||||||
|
var container = new UnityContainer();
|
||||||
|
|
||||||
private static IUnityContainer CreateContainer()
|
container.AddExtension(new LoggingExtension(CreateLoggerFactory()));
|
||||||
{
|
|
||||||
var container = new UnityContainer();
|
|
||||||
|
|
||||||
container.AddExtension(new LoggingExtension(CreateLoggerFactory()));
|
container.RegisterType<IOrderRepository, OrderRepository>();
|
||||||
|
container.RegisterType<IAppointmentRepository, AppointmentRepository>();
|
||||||
container.RegisterType<IOrderRepository, OrderRepository>();
|
container.RegisterType<IServiceRepository, ServiceRepository>();
|
||||||
container.RegisterType<IAppointmentRepository, AppointmentRepository>();
|
container.RegisterType<IEmployeeRepository, EmployeeRepository>();
|
||||||
container.RegisterType<IServiceRepository, ServiceRepository>();
|
container.RegisterType<ICompanyRepository, CompanyRepository>();
|
||||||
container.RegisterType<IEmployeeRepository, EmployeeRepository>();
|
|
||||||
container.RegisterType<ICompanyRepository, CompanyRepository>();
|
|
||||||
|
|
||||||
container.RegisterType<IConnectionString, ConnectionString>();
|
container.RegisterType<IConnectionString, ConnectionString>();
|
||||||
|
|
||||||
return container;
|
return container;
|
||||||
}
|
|
||||||
|
|
||||||
private static LoggerFactory CreateLoggerFactory()
|
|
||||||
{
|
|
||||||
var loggerFactory = new LoggerFactory();
|
|
||||||
loggerFactory.AddSerilog(new LoggerConfiguration()
|
|
||||||
.ReadFrom.Configuration(new ConfigurationBuilder()
|
|
||||||
.SetBasePath(Directory.GetCurrentDirectory())
|
|
||||||
.AddJsonFile("appsettings.json")
|
|
||||||
.Build())
|
|
||||||
.CreateLogger());
|
|
||||||
return loggerFactory;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
private static LoggerFactory CreateLoggerFactory()
|
||||||
|
{
|
||||||
|
var loggerFactory = new LoggerFactory();
|
||||||
|
loggerFactory.AddSerilog(new LoggerConfiguration()
|
||||||
|
.ReadFrom.Configuration(new ConfigurationBuilder()
|
||||||
|
.SetBasePath(Directory.GetCurrentDirectory())
|
||||||
|
.AddJsonFile("appsettings.json")
|
||||||
|
.Build())
|
||||||
|
.CreateLogger());
|
||||||
|
return loggerFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user