166 lines
4.2 KiB
C#
166 lines
4.2 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 LearnForm : Form
|
||
{
|
||
private readonly ColumnConf[] tableMainColumns = {
|
||
new ColumnConf(name: "№"),
|
||
new ColumnConf(name: "Название обр. учр.", size: 140, warp: true),
|
||
new ColumnConf(name: "Уровень", size: 140),
|
||
new ColumnConf(name: "Специальность", size: 140),
|
||
new ColumnConf(name: "Дата окончания", size: 80),
|
||
new ColumnConf(name: "Курсы", size: 140, warp: true),
|
||
new ColumnConf(name: "Проф. переподготовка", size: 140, warp: true)
|
||
};
|
||
|
||
private Rabotnik rabotnik = null;
|
||
private void linkRabLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
|
||
{
|
||
var form = new RabForm(true);
|
||
form.ShowDialog();
|
||
if (form.isCanceled)
|
||
rabotnik = null;
|
||
else
|
||
rabotnik = form.formResult;
|
||
ResetLinkRabotnik();
|
||
resetLearnTable();
|
||
}
|
||
private void ResetLinkRabotnik()
|
||
{
|
||
if (rabotnik == null)
|
||
{
|
||
linkRabLabel.Text = "Выбрать сотрудника...";
|
||
return;
|
||
}
|
||
var chel = FuncDB.ChelGetById(rabotnik.ChelId);
|
||
if (chel == null)
|
||
{
|
||
linkRabLabel.Text = "Выбрать сотрудника...";
|
||
return;
|
||
}
|
||
var res = chel.FName.ToString() + " " +
|
||
chel.SName[0].ToString() + "." +
|
||
((!string.IsNullOrEmpty(chel.TName)) ?
|
||
chel.TName[0].ToString() + "." : "");
|
||
linkRabLabel.Text = res;
|
||
}
|
||
|
||
private void resetLearnTable()
|
||
{
|
||
try
|
||
{
|
||
var res = rabotnik == null ? Array.Empty<string[]>() : FuncDB.LearnListTableMain(rabotnik.ChelId);
|
||
this.ResetTable(
|
||
learnGridView,
|
||
tableMainColumns,
|
||
res
|
||
);
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
this.ShowError(errorLabel, e.Message);
|
||
}
|
||
}
|
||
private Learn selectedLearnTable()
|
||
{
|
||
try
|
||
{
|
||
if (learnGridView.SelectedRows.Count != 1)
|
||
throw new Exception("Образование не выбрано.");
|
||
if (int.TryParse((string)learnGridView.SelectedRows[0].Cells[0].Value, out int value))
|
||
return FuncDB.LearnGetById(value);
|
||
else
|
||
throw new Exception("Ошибка в таблице.");
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
this.ShowError(errorLabel, e.Message);
|
||
return null;
|
||
}
|
||
}
|
||
|
||
public LearnForm()
|
||
{
|
||
InitializeComponent();
|
||
this.correctUpperMenu(menuStrip, 4);
|
||
ResetLinkRabotnik();
|
||
resetLearnTable();
|
||
|
||
linkRabLabel.Enabled =
|
||
addButton.Enabled =
|
||
changeButton.Enabled =
|
||
delButton.Enabled = false;
|
||
|
||
var user = this.GetUser();
|
||
if (user == null)
|
||
return;
|
||
linkRabLabel.Enabled = FuncDB.AccessGetByUserIdFormIdAccessId(user.Id, 4, 0) != null;
|
||
delButton.Enabled = FuncDB.AccessGetByUserIdFormIdAccessId(user.Id, 4, 1) != null;
|
||
changeButton.Enabled = FuncDB.AccessGetByUserIdFormIdAccessId(user.Id, 4, 2) != null;
|
||
addButton.Enabled = FuncDB.AccessGetByUserIdFormIdAccessId(user.Id, 4, 3) != null;
|
||
}
|
||
|
||
private void addButton_Click(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
if (rabotnik == null)
|
||
throw new Exception("Не выбран сотрудник.");
|
||
var form = new SupportForms.LearnForm(chelId: rabotnik.ChelId);
|
||
form.ShowDialog();
|
||
if (!form.isCanceled)
|
||
{
|
||
resetLearnTable();
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
this.ShowError(errorLabel, ex.Message);
|
||
}
|
||
}
|
||
private void changeButton_Click(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
var form = new SupportForms.LearnForm(selectedLearnTable());
|
||
form.ShowDialog();
|
||
if (!form.isCanceled)
|
||
resetLearnTable();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
this.ShowError(errorLabel, ex.Message);
|
||
}
|
||
}
|
||
private void delButton_Click(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
FuncDB.LearnDelete(selectedLearnTable());
|
||
resetLearnTable();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
this.ShowError(errorLabel, ex.Message);
|
||
}
|
||
}
|
||
|
||
private void upperMenuClicked(object sender, ToolStripItemClickedEventArgs e)
|
||
{
|
||
this.upperMenuClicked((MenuStrip)sender);
|
||
if (this.GetNextForm() != -1)
|
||
Close();
|
||
}
|
||
}
|
||
}
|