130 lines
4.9 KiB
C#
130 lines
4.9 KiB
C#
|
using database;
|
|||
|
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 Forms
|
|||
|
{
|
|||
|
public partial class FormEmployees : Form
|
|||
|
{
|
|||
|
private Abstractions bd;
|
|||
|
public FormEmployees(Abstractions _bd)
|
|||
|
{
|
|||
|
InitializeComponent();
|
|||
|
bd = _bd;
|
|||
|
}
|
|||
|
|
|||
|
private void loadData()
|
|||
|
{
|
|||
|
// Получаем список сотрудников
|
|||
|
List<Employee> employees = bd.GetEmployees();
|
|||
|
|
|||
|
// Очищаем dataGridView перед заполнением новыми данными
|
|||
|
dataGridView.Rows.Clear();
|
|||
|
|
|||
|
// Предварительно определяем столбцы, если это не было сделано ранее
|
|||
|
if (dataGridView.ColumnCount == 0)
|
|||
|
{
|
|||
|
dataGridView.Columns.Add("Id", "ID");
|
|||
|
dataGridView.Columns.Add("Name", "Name");
|
|||
|
dataGridView.Columns.Add("Surname", "Surname");
|
|||
|
dataGridView.Columns.Add("Position", "Position");
|
|||
|
dataGridView.Columns.Add("Timework", "Timework");
|
|||
|
dataGridView.Columns.Add("Seniority", "Seniority");
|
|||
|
dataGridView.Columns.Add("CostPerHour", "CostPerHour");
|
|||
|
}
|
|||
|
|
|||
|
// Заполняем dataGridView данными из списка сотрудников
|
|||
|
foreach (Employee employee in employees)
|
|||
|
{
|
|||
|
dataGridView.Rows.Add(employee.Id, employee.Name, employee.Surname, employee.Position, employee.Timework, employee.Seniority, employee.CostPerHour);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
// Создание новой записи сотрудника
|
|||
|
private void buttonCreate_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
Employee newEmployee = new Employee
|
|||
|
{
|
|||
|
Name = textBoxName.Text,
|
|||
|
Surname = textBoxSurnName.Text,
|
|||
|
Position = textBoxPosition.Text,
|
|||
|
Timework = textBoxTimeWork.Text,
|
|||
|
Seniority = textBoxSeniority.Text,
|
|||
|
CostPerHour = decimal.Parse(textBoxCostPerHour.Text)
|
|||
|
};
|
|||
|
|
|||
|
bd.AddEmployee(newEmployee);
|
|||
|
// Обновляем отображение данных
|
|||
|
loadData();
|
|||
|
// Очищаем текстовые поля после добавления сотрудника
|
|||
|
}
|
|||
|
|
|||
|
// Обновление выбранной записи сотрудника
|
|||
|
private void buttonUpdate_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
if (dataGridView.SelectedRows.Count > 0)
|
|||
|
{
|
|||
|
DataGridViewRow row = dataGridView.SelectedRows[0];
|
|||
|
int employeeId = Convert.ToInt32(row.Cells["Id"].Value);
|
|||
|
|
|||
|
Employee updatedEmployee = new Employee
|
|||
|
{
|
|||
|
Id = employeeId,
|
|||
|
Name = textBoxName.Text,
|
|||
|
Surname = textBoxSurnName.Text,
|
|||
|
Position = textBoxPosition.Text,
|
|||
|
Timework = textBoxTimeWork.Text,
|
|||
|
Seniority = textBoxSeniority.Text,
|
|||
|
CostPerHour = decimal.Parse(textBoxCostPerHour.Text)
|
|||
|
};
|
|||
|
|
|||
|
bd.UpdateEmployee(updatedEmployee);
|
|||
|
// Обновляем отображение данных
|
|||
|
loadData();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
// Удаление выбранной записи сотрудника
|
|||
|
private void buttonDelete_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
if (dataGridView.SelectedRows.Count > 0)
|
|||
|
{
|
|||
|
DataGridViewRow row = dataGridView.SelectedRows[0];
|
|||
|
int employeeId = Convert.ToInt32(row.Cells["Id"].Value);
|
|||
|
|
|||
|
bd.DeleteEmployee(employeeId);
|
|||
|
// Обновляем отображение данных
|
|||
|
loadData();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void FormEmployees_Load(object sender, EventArgs e)
|
|||
|
{
|
|||
|
loadData();
|
|||
|
}
|
|||
|
|
|||
|
private void dataGridView_CellClick(object sender, DataGridViewCellEventArgs e)
|
|||
|
{
|
|||
|
if (e.RowIndex >= 0)
|
|||
|
{
|
|||
|
DataGridViewRow row = dataGridView.Rows[e.RowIndex];
|
|||
|
|
|||
|
textBoxName.Text = row.Cells["Name"].Value.ToString();
|
|||
|
textBoxSurnName.Text = row.Cells["Surname"].Value.ToString();
|
|||
|
textBoxPosition.Text = row.Cells["Position"].Value.ToString();
|
|||
|
textBoxTimeWork.Text = row.Cells["Timework"].Value.ToString();
|
|||
|
textBoxSeniority.Text = row.Cells["Seniority"].Value.ToString();
|
|||
|
textBoxCostPerHour.Text = row.Cells["CostPerHour"].Value.ToString();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
}
|