201 lines
6.8 KiB
C#
201 lines
6.8 KiB
C#
using Microsoft.EntityFrameworkCore.Diagnostics;
|
|
using HotelContracts.BindingModels;
|
|
using HotelContracts.BusinessLogicsContracts;
|
|
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 HotelContracts.SearchModels;
|
|
using HotelDatabaseImplement.Models;
|
|
|
|
namespace HotelView
|
|
{
|
|
public partial class FormRooms : Form
|
|
{
|
|
private readonly IRoomLogic _logic;
|
|
private readonly IWorkerLogic _logicW;
|
|
public FormRooms(IRoomLogic logic, IWorkerLogic logicW)
|
|
{
|
|
InitializeComponent();
|
|
_logic = logic;
|
|
_logicW = logicW;
|
|
|
|
}
|
|
|
|
private void FormBuyers_Load(object sender, EventArgs e)
|
|
{
|
|
LoadData();
|
|
}
|
|
|
|
private void LoadData()
|
|
{
|
|
try
|
|
{
|
|
var list = _logic.ReadList(null);
|
|
if (list != null)
|
|
{
|
|
dataGridView.DataSource = list;
|
|
dataGridView.Columns["Id"].Visible = false;
|
|
dataGridView.Columns["WorkerId"].Visible = false;
|
|
dataGridView.Columns["WorkerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
}
|
|
}
|
|
|
|
private void buttonAdd_Click(object sender, EventArgs e)
|
|
{
|
|
var service = Program.ServiceProvider?.GetService(typeof(FormRoom));
|
|
if (service is FormRoom form)
|
|
{
|
|
if (form.ShowDialog() == DialogResult.OK)
|
|
{
|
|
LoadData();
|
|
}
|
|
}
|
|
}
|
|
|
|
private void buttonUpd_Click(object sender, EventArgs e)
|
|
{
|
|
if (dataGridView.SelectedRows.Count == 1)
|
|
{
|
|
var service = Program.ServiceProvider?.GetService(typeof(FormRoom));
|
|
if (service is FormRoom form)
|
|
{
|
|
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
|
if (form.ShowDialog() == DialogResult.OK)
|
|
{
|
|
LoadData();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void buttonDel_Click(object sender, EventArgs e)
|
|
{
|
|
if (dataGridView.SelectedRows.Count == 1)
|
|
{
|
|
if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
|
{
|
|
int number = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Number"].Value);
|
|
try
|
|
{
|
|
if (!_logic.Delete(new RoomBindingModel { Number = number }))
|
|
{
|
|
throw new Exception("Ошибка при удалении. Доп информация в логах");
|
|
}
|
|
LoadData();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void button1_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
DateTime start = DateTime.Now;
|
|
var element = _logicW.ReadElement(new WorkerSearchModel
|
|
{
|
|
FIO = "Паша Пашок Паша"
|
|
});
|
|
for (int i = 1; i < 1001; i++)
|
|
{
|
|
var operationResult = _logic.Create(new RoomBindingModel
|
|
{
|
|
WorkerId = element?.Id ?? 0,
|
|
Number = i,
|
|
Floor = 1,
|
|
NumberOfBeds = 4,
|
|
Condition = "Норм",
|
|
Cost = 350
|
|
});
|
|
}
|
|
DateTime stop = DateTime.Now;
|
|
LoadData();
|
|
MessageBox.Show((stop - start).Milliseconds.ToString(), "Test", MessageBoxButtons.OK);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
|
|
MessageBoxIcon.Error);
|
|
}
|
|
}
|
|
|
|
private void button2_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
DateTime start = DateTime.Now;
|
|
int Number = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Number"].Value);
|
|
var element = _logic.ReadElement(new RoomSearchModel
|
|
{
|
|
Number = Number
|
|
});
|
|
for (int i = Number; i < Number + 1000; i++)
|
|
{
|
|
var operationResult = _logic.Delete(new RoomBindingModel
|
|
{
|
|
Number = i
|
|
});
|
|
}
|
|
DateTime stop = DateTime.Now;
|
|
LoadData();
|
|
MessageBox.Show((stop - start).Milliseconds.ToString(), "Test", MessageBoxButtons.OK);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
|
|
MessageBoxIcon.Error);
|
|
}
|
|
}
|
|
|
|
private void button3_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
DateTime start = DateTime.Now;
|
|
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
|
var element = _logic.ReadElement(new RoomSearchModel
|
|
{
|
|
Id = id
|
|
});
|
|
for (int i = id; i < id + 1000; i++)
|
|
{
|
|
var operationResult = _logic.Update(new RoomBindingModel
|
|
{
|
|
Id = i,
|
|
WorkerId = element?.Id ?? 0,
|
|
Number = i+1000,
|
|
Floor = 2,
|
|
NumberOfBeds = 5,
|
|
Condition = "Отличненько",
|
|
Cost = 400
|
|
});
|
|
|
|
}
|
|
DateTime stop = DateTime.Now;
|
|
LoadData();
|
|
MessageBox.Show((stop - start).Milliseconds.ToString(), "Test", MessageBoxButtons.OK);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
|
|
MessageBoxIcon.Error);
|
|
}
|
|
}
|
|
}
|
|
}
|