293 lines
7.5 KiB
C#
293 lines
7.5 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 RabForm : 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 rab = FuncDB.RabotnikTableMain(findBox.Text);
|
||
var res = new List<string[]>();
|
||
foreach (var r in rab)
|
||
{
|
||
bool flag_add = false;
|
||
foreach (var a in r)
|
||
if (a.Contains(findBox.Text) && !flag_add)
|
||
{
|
||
res.Add(r);
|
||
flag_add = true;
|
||
}
|
||
}
|
||
this.ResetTable(
|
||
workerGridView,
|
||
tableMainColumns,
|
||
res.ToArray()
|
||
);
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
this.ShowError(errorLabel, e.Message);
|
||
}
|
||
}
|
||
private Rabotnik selectedRabotnikTable()
|
||
{
|
||
try
|
||
{
|
||
if (workerGridView.RowCount == 0)
|
||
return null;
|
||
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.RowCount == 0)
|
||
return null;
|
||
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 bool isCanceled = true;
|
||
public Rabotnik formResult = null;
|
||
public RabForm(bool select = false)
|
||
{
|
||
InitializeComponent();
|
||
selectButton.Visible = select;
|
||
menuStrip.Enabled = !select;
|
||
this.correctUpperMenu(menuStrip, 2);
|
||
resetRabotnikTable();
|
||
resetTypeStajComboBox();
|
||
|
||
addTypeStajButton.Enabled =
|
||
delTypeStajButton.Enabled =
|
||
delWorkPlaceButton.Enabled =
|
||
changeWorkPlaceButton.Enabled =
|
||
addWorkPlaceButton.Enabled =
|
||
addWorkerButton.Enabled = false;
|
||
var user = this.GetUser();
|
||
if (user == null)
|
||
return;
|
||
|
||
delWorkPlaceButton.Enabled = FuncDB.AccessGetByUserIdFormIdAccessId(user.Id, 2, 1) != null;
|
||
changeWorkPlaceButton.Enabled =
|
||
delTypeStajButton.Enabled =
|
||
addTypeStajButton.Enabled = FuncDB.AccessGetByUserIdFormIdAccessId(user.Id, 2, 2) != null;
|
||
addWorkerButton.Enabled =
|
||
addWorkPlaceButton.Enabled = FuncDB.AccessGetByUserIdFormIdAccessId(user.Id, 2, 3) != null;
|
||
|
||
}
|
||
|
||
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();
|
||
}
|
||
|
||
private void selectButton_Click(object sender, EventArgs e)
|
||
{
|
||
formResult = selectedRabotnikTable();
|
||
isCanceled = false;
|
||
this.Close();
|
||
}
|
||
|
||
private void findBox_TextChanged(object sender, EventArgs e)
|
||
{
|
||
this.FindOnChanged(resetRabotnikTable);
|
||
}
|
||
private void dropFindButton_Click(object sender, EventArgs e)
|
||
{
|
||
findBox.Text = "";
|
||
this.FindOnChanged(null);
|
||
resetRabotnikTable();
|
||
}
|
||
|
||
|
||
}
|
||
}
|