Diplom_O/MainForms/ShtatForm.cs

155 lines
3.5 KiB
C#
Raw Permalink 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;
using Diplom_O.DataBase;
namespace Diplom_O
{
public partial class ShtatForm : Form
{
2024-09-20 08:53:52 +05:00
private readonly ColumnConf[] tableColumns =
2021-07-21 16:57:47 +05:00
{
2024-09-20 08:53:52 +05:00
new ColumnConf("№"),
new ColumnConf("Должность", 140),
new ColumnConf(name: "Кол-во"),
new ColumnConf(name: "Своб.")
};
2021-07-21 16:57:47 +05:00
private void findBox_TextChanged(object sender, EventArgs e)
{
2024-09-20 08:53:52 +05:00
this.FindOnChanged(resetShatTable);
2021-07-21 16:57:47 +05:00
}
private void dropFindButton_Click(object sender, EventArgs e)
{
findBox.Text = "";
2024-09-20 08:53:52 +05:00
this.FindOnChanged(null);
2021-07-21 16:57:47 +05:00
resetShatTable();
}
private void resetShatTable()
{
try
{
2024-09-20 08:53:52 +05:00
var tmp = FuncDB.ShtatListTableMain(findBox.Text, freeShtatCheckBox.Checked);
var res = new List<string[]>();
foreach (var i in tmp)
if (int.TryParse(i[0], out int t) && t != 0)
res.Add(i);
this.ResetTable(
shtatGridView,
tableColumns,
freeShtatCheckBox.Checked ?
tmp :
res.ToArray()
);
}
catch ( Exception e )
{
this.ShowError( errorLabel, e.Message );
2021-07-21 16:57:47 +05:00
}
}
private Shtat selectedShtat()
{
try
{
2024-09-20 08:53:52 +05:00
if ( shtatGridView.SelectedRows.Count != 1 )
throw new Exception("Должность не выбрана.");
if (int.TryParse((string)shtatGridView.SelectedRows[0].Cells[0].Value, out int value))
return FuncDB.ShtatGetById(value);
else
throw new Exception("Ошибка в таблице.");
}
catch (Exception e)
{
this.ShowError(errorLabel, e.Message);
return null;
2021-07-21 16:57:47 +05:00
}
}
2024-09-20 08:53:52 +05:00
public bool isCanceled = true;
2021-07-21 16:57:47 +05:00
public Shtat formResult = null;
public ShtatForm(bool select = false)
{
try
{
InitializeComponent();
2024-09-20 08:53:52 +05:00
selectButton.Visible = select;
shtatMI.Enabled = !select;
this.correctUpperMenu(menuStrip, 0);
2021-07-21 16:57:47 +05:00
resetShatTable();
2024-09-20 08:53:52 +05:00
addButton.Enabled =
changeButton.Enabled =
delButton.Enabled = false;
var user = this.GetUser();
if (user == null)
return;
delButton.Enabled = FuncDB.AccessGetByUserIdFormIdAccessId(user.Id, 0, 1) != null;
changeButton.Enabled = FuncDB.AccessGetByUserIdFormIdAccessId(user.Id, 0, 2) != null;
addButton.Enabled = FuncDB.AccessGetByUserIdFormIdAccessId(user.Id, 0, 3) != null;
2021-07-21 16:57:47 +05:00
}
catch { this.Close(); }
}
2024-09-20 08:53:52 +05:00
2021-07-21 16:57:47 +05:00
private void addButton_Click(object sender, EventArgs e)
{
var res = new SupportForms.WorkShtatForm();
res.ShowDialog();
if (!res.isCanceled)
resetShatTable();
}
private void changeButton_Click(object sender, EventArgs e)
{
var shtat = selectedShtat();
2024-09-20 08:53:52 +05:00
if (shtat == null)
return;
2021-07-21 16:57:47 +05:00
var res = new SupportForms.WorkShtatForm(shtat);
res.ShowDialog();
if (!res.isCanceled)
resetShatTable();
}
private void delButton_Click(object sender, EventArgs e)
{
var shtat = selectedShtat();
2024-09-20 08:53:52 +05:00
if (shtat == null)
return;
2021-07-21 16:57:47 +05:00
try
{
2024-09-20 08:53:52 +05:00
FuncDB.ShtatDelete(shtat);
2021-07-21 16:57:47 +05:00
resetShatTable();
}
2024-09-20 08:53:52 +05:00
catch (Exception ex)
2021-07-21 16:57:47 +05:00
{
2024-09-20 08:53:52 +05:00
this.ShowError(errorLabel, ex.Message);
2021-07-21 16:57:47 +05:00
}
2024-09-20 08:53:52 +05:00
}
private void selectButton_Click(object sender, EventArgs e)
{
formResult = selectedShtat();
isCanceled = false;
this.Close();
2021-07-21 16:57:47 +05:00
}
2021-07-23 16:44:42 +05:00
private void checkBox_CheckedChanged(object sender, EventArgs e)
2021-07-21 16:57:47 +05:00
{
resetShatTable();
}
2024-09-20 08:53:52 +05:00
private void upperMenuClicked(object sender, ToolStripItemClickedEventArgs e)
{
this.upperMenuClicked((MenuStrip)sender);
if (this.GetNextForm() != -1)
Close();
}
}
2021-07-21 16:57:47 +05:00
}