238 lines
6.0 KiB
C#
238 lines
6.0 KiB
C#
|
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 Diplom_O.DataBase;
|
|||
|
|
|||
|
namespace Diplom_O
|
|||
|
{
|
|||
|
public partial class ChildrenForm : Form
|
|||
|
{
|
|||
|
private readonly ColumnConf[] tableMainColumns = {
|
|||
|
new ColumnConf(name: "№"),
|
|||
|
new ColumnConf(name: "Таб. №", size: 80),
|
|||
|
new ColumnConf(name: "Фамилия И.О.", size: 140),
|
|||
|
new ColumnConf(name: "Должность", size: 140)
|
|||
|
};
|
|||
|
private readonly ColumnConf[] tableHistoryColumns =
|
|||
|
{
|
|||
|
new ColumnConf(name: "№"),
|
|||
|
new ColumnConf(name: "Таб. №", size: 80),
|
|||
|
new ColumnConf(name: "Должность", size: 140),
|
|||
|
new ColumnConf(name: "Дата начала", size: 80),
|
|||
|
new ColumnConf(name: "Дата конца", size: 80)
|
|||
|
};
|
|||
|
private readonly ColumnConf[] tableStajColumns =
|
|||
|
{
|
|||
|
new ColumnConf(name: "№"),
|
|||
|
new ColumnConf(name: "Тип стажа", size: 120),
|
|||
|
};
|
|||
|
|
|||
|
private void resetRabotnikTable()
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
var res = FuncDB.RabotnikTableMain(findBox.Text);
|
|||
|
this.ResetTable(
|
|||
|
workerGridView,
|
|||
|
tableMainColumns,
|
|||
|
res
|
|||
|
);
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
this.ShowError(errorLabel, e.Message);
|
|||
|
}
|
|||
|
}
|
|||
|
private Rabotnik selectedRabotnikTable()
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
if (workerGridView.SelectedRows.Count != 1)
|
|||
|
throw new Exception("Человек не выбран.");
|
|||
|
if (int.TryParse((string)workerGridView.SelectedRows[0].Cells[0].Value, out int value))
|
|||
|
return FuncDB.RabotnikGetById(value);
|
|||
|
else
|
|||
|
throw new Exception("Ошибка в таблице.");
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
this.ShowError(errorLabel, e.Message);
|
|||
|
return null;
|
|||
|
}
|
|||
|
}
|
|||
|
private void workerGridView_SelectionChanged(object sender, EventArgs e)
|
|||
|
{
|
|||
|
resetHistoryWorkTable();
|
|||
|
}
|
|||
|
|
|||
|
private void resetHistoryWorkTable()
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
var rabotnik = selectedRabotnikTable();
|
|||
|
var res = (rabotnik == null) ? Array.Empty<string[]>() : FuncDB.RabotnikByChelIdTable(rabotnik.ChelId);
|
|||
|
this.ResetTable(
|
|||
|
historyWorkGridView,
|
|||
|
tableHistoryColumns,
|
|||
|
res
|
|||
|
);
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
this.ShowError(errorLabel, e.Message);
|
|||
|
}
|
|||
|
}
|
|||
|
private Rabotnik selectedHistoryWorkTable()
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
if (historyWorkGridView.SelectedRows.Count != 1)
|
|||
|
throw new Exception("Человек не выбран.");
|
|||
|
if (int.TryParse((string)historyWorkGridView.SelectedRows[0].Cells[0].Value, out int value))
|
|||
|
return FuncDB.RabotnikGetById(value);
|
|||
|
else
|
|||
|
throw new Exception("Ошибка в таблице.");
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
this.ShowError(errorLabel, e.Message);
|
|||
|
return null;
|
|||
|
}
|
|||
|
}
|
|||
|
private void historyWorkGridView_SelectionChanged(object sender, EventArgs e)
|
|||
|
{
|
|||
|
resetRabotnikStajTable();
|
|||
|
}
|
|||
|
|
|||
|
private void resetRabotnikStajTable()
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
var rabotnik = selectedHistoryWorkTable();
|
|||
|
var res = (rabotnik == null) ? Array.Empty<string[]>() :
|
|||
|
FuncDB.RabotnikTypeStajListString(rabotnik.Id);
|
|||
|
this.ResetTable(
|
|||
|
stajGridView,
|
|||
|
tableStajColumns,
|
|||
|
res
|
|||
|
);
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
this.ShowError(errorLabel, e.Message);
|
|||
|
}
|
|||
|
}
|
|||
|
private RabotnikTypeStaj selectedRabotnikStajTable()
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
if (stajGridView.SelectedRows.Count != 1)
|
|||
|
throw new Exception("Стаж сотрудника не выбран.");
|
|||
|
if (int.TryParse((string)stajGridView.SelectedRows[0].Cells[0].Value, out int value))
|
|||
|
return FuncDB.RabotnikTypeStajGetById(value);
|
|||
|
else
|
|||
|
throw new Exception("Ошибка в таблице.");
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
this.ShowError(errorLabel, e.Message);
|
|||
|
return null;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void resetTypeStajComboBox()
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
var list = FuncDB.TypeStajListString();
|
|||
|
comboBox1.Items.Clear();
|
|||
|
comboBox1.Items.AddRange(list);
|
|||
|
comboBox1.SelectedIndex = -1;
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
this.ShowError(errorLabel, e.Message);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public RabForm()
|
|||
|
{
|
|||
|
InitializeComponent();
|
|||
|
this.correctUpperMenu(menuStrip, 1);
|
|||
|
resetRabotnikTable();
|
|||
|
resetTypeStajComboBox();
|
|||
|
}
|
|||
|
|
|||
|
private void addWorkerButton_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
var form = new SupportForms.WorkerForm();
|
|||
|
form.ShowDialog();
|
|||
|
if (!form.isCanceled)
|
|||
|
resetRabotnikTable();
|
|||
|
}
|
|||
|
private void addWorkPlaceButton_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
var form = new SupportForms.WorkerForm(selectedHistoryWorkTable(), true);
|
|||
|
form.ShowDialog();
|
|||
|
if (!form.isCanceled)
|
|||
|
resetRabotnikTable();
|
|||
|
}
|
|||
|
private void addTypeStajButton_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
var typestaj = FuncDB.TypeStajGetByName(comboBox1.Text);
|
|||
|
if (typestaj == null)
|
|||
|
{
|
|||
|
FuncDB.TypeStajAdd(new TypeStaj() { Name = comboBox1.Text });
|
|||
|
typestaj = FuncDB.TypeStajGetByName(comboBox1.Text);
|
|||
|
}
|
|||
|
var rabotnik = selectedHistoryWorkTable();
|
|||
|
if (rabotnik == null)
|
|||
|
throw new Exception("Не выбран сотрудник");
|
|||
|
FuncDB.RabotnikTypeStajAdd(new RabotnikTypeStaj() { RabitnikId = rabotnik.Id, TypeStajId = typestaj.Id });
|
|||
|
resetTypeStajComboBox();
|
|||
|
resetRabotnikStajTable();
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
this.ShowError(errorLabel, ex.Message);
|
|||
|
}
|
|||
|
}
|
|||
|
private void changeWorkPlaceButton_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
var form = new SupportForms.WorkerForm(selectedHistoryWorkTable());
|
|||
|
form.ShowDialog();
|
|||
|
if (!form.isCanceled)
|
|||
|
resetRabotnikTable();
|
|||
|
}
|
|||
|
private void delWorkPlaceButton_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
var res = selectedHistoryWorkTable();
|
|||
|
FuncDB.RabotnikDelete(res);
|
|||
|
resetHistoryWorkTable();
|
|||
|
}
|
|||
|
private void delTypeStajButton_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
var res = selectedRabotnikStajTable();
|
|||
|
FuncDB.RabotnikTypeStajDelete(res);
|
|||
|
resetRabotnikStajTable();
|
|||
|
}
|
|||
|
|
|||
|
private void upperMenuClicked(object sender, ToolStripItemClickedEventArgs e)
|
|||
|
{
|
|||
|
this.upperMenuClicked((MenuStrip)sender);
|
|||
|
if (this.GetNextForm() != -1)
|
|||
|
Close();
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
}
|