Diplom_O/MainForms/OtpForm.cs

208 lines
5.2 KiB
C#
Raw Normal View History

2021-07-21 16:57:47 +05:00
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;
2024-09-20 08:53:52 +05:00
using Diplom_O.DataBase;
2021-07-21 16:57:47 +05:00
namespace Diplom_O
{
public partial class OtpForm : Form
{
2024-09-20 08:53:52 +05:00
private readonly ColumnConf[] tableMainColumns = {
new ColumnConf(name: "№"),
new ColumnConf(name: "Тип", size: 140, warp: true),
new ColumnConf(name: "Дата начала", size: 80),
new ColumnConf(name: "Дата конца", size: 80),
new ColumnConf(name: "Общее кол-во дней", size: 100)
};
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();
resetFreeTable();
resetFreeDays();
}
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 resetFreeTable()
{
try
{
var res = rabotnik == null ? Array.Empty<string[]>() : FuncDB.FreeListTable(rabotnik.ChelId, dateTimePicker1.Value, dateTimePicker2.Value);
this.ResetTable(
freeGridView,
tableMainColumns,
res
);
}
catch (Exception e)
{
this.ShowError(errorLabel, e.Message);
}
}
private void resetFreeDays()
{
try
{
var res = rabotnik == null ? new Dictionary<string, int>() : FuncDB.FreeListDays(rabotnik.ChelId, dateTimePicker1.Value, dateTimePicker2.Value);
if (res.ContainsKey("Общее"))
totalDaysLabel.Text = res["Общее"].ToString();
else
totalDaysLabel.Text = "0";
if (res.ContainsKey("Отпуск"))
otpDaysLabel.Text = res["Отпуск"].ToString();
else
otpDaysLabel.Text = "0";
if (res.ContainsKey("Больничный"))
bolDaysLabel.Text = res["Больничный"].ToString();
else
bolDaysLabel.Text = "0";
if (res.ContainsKey("Иное"))
otherDaysLabel.Text = res["Иное"].ToString();
else
otherDaysLabel.Text = "0";
}
catch (Exception e)
{
this.ShowError(errorLabel, e.Message);
}
}
private Free selectedFreeTable()
{
try
{
if (freeGridView.SelectedRows.Count != 1)
throw new Exception("Отстранение не выбрано.");
if (int.TryParse((string)freeGridView.SelectedRows[0].Cells[0].Value, out int value))
return FuncDB.FreeGetById(value);
else
throw new Exception("Ошибка в таблице.");
}
catch (Exception e)
{
this.ShowError(errorLabel, e.Message);
return null;
}
}
2021-07-21 16:57:47 +05:00
public OtpForm()
{
InitializeComponent();
2024-09-20 08:53:52 +05:00
this.correctUpperMenu(menuStrip, 5);
DateTime d = DateTime.Now;
dateTimePicker1.Value = new DateTime(d.Year, 1, 1, 0, 0, 0);
dateTimePicker2.Value = new DateTime(d.Year + 1, 1, 1, 0, 0, 0);
ResetLinkRabotnik();
resetFreeTable();
resetFreeDays();
linkRabLabel.Enabled =
addButton.Enabled =
changeButton.Enabled =
delButton.Enabled = false;
var user = this.GetUser();
if (user == null)
return;
linkRabLabel.Enabled = FuncDB.AccessGetByUserIdFormIdAccessId(user.Id, 5, 0) != null;
delButton.Enabled = FuncDB.AccessGetByUserIdFormIdAccessId(user.Id, 5, 1) != null;
changeButton.Enabled = FuncDB.AccessGetByUserIdFormIdAccessId(user.Id, 5, 2) != null;
addButton.Enabled = FuncDB.AccessGetByUserIdFormIdAccessId(user.Id, 5, 3) != null;
}
private void addButton_Click(object sender, EventArgs e)
{
try
{
if (rabotnik == null)
throw new Exception("Не выбран сотрудник.");
var form = new SupportForms.OptForm(chelId: rabotnik.ChelId);
form.ShowDialog();
if (!form.isCanceled)
{
resetFreeTable();
resetFreeDays();
}
}
catch (Exception ex)
{
this.ShowError(errorLabel, ex.Message);
}
}
private void changeButton_Click(object sender, EventArgs e)
{
try
{
var form = new SupportForms.OptForm(selectedFreeTable());
form.ShowDialog();
if (!form.isCanceled)
{
resetFreeTable();
resetFreeDays();
}
}
catch (Exception ex)
{
this.ShowError(errorLabel, ex.Message);
}
2021-07-21 16:57:47 +05:00
}
2024-09-20 08:53:52 +05:00
private void delButton_Click(object sender, EventArgs e)
{
try
{
FuncDB.FreeDelete(selectedFreeTable());
resetFreeTable();
resetFreeDays();
}
catch (Exception ex)
{
this.ShowError(errorLabel, ex.Message);
}
}
private void upperMenuClicked(object sender, ToolStripItemClickedEventArgs e)
{
this.upperMenuClicked((MenuStrip)sender);
if (this.GetNextForm() != -1)
Close();
}
private void updateButton_Click(object sender, EventArgs e)
{
resetFreeTable();
resetFreeDays();
}
}
2021-07-21 16:57:47 +05:00
}