Diplom_O/MainForms/ChelForm.cs
2024-09-20 06:53:52 +03:00

148 lines
3.7 KiB
C#

using Diplom_O.DataBase;
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;
namespace Diplom_O
{
public partial class ChelForm : Form
{
private readonly ColumnConf[] tableColumns = {
new ColumnConf(name: "№"),
new ColumnConf("Фамилия", 140),
new ColumnConf("Имя", 140),
new ColumnConf("Отчество", 140),
new ColumnConf(name: "Пол"),
new ColumnConf(name: "Дата рождения", size: 80),
new ColumnConf(name: "Адрес", size: 140, warp: true),
new ColumnConf(name: "Телефон", size: 100),
new ColumnConf(name: "ИНН", size: 100),
new ColumnConf(name: "СНИЛС", size: 100),
new ColumnConf(name: "Паспорт", size: 140, warp: true),
new ColumnConf(name: "Пенсионер", size: 100)
};
private void findBox_TextChanged(object sender, EventArgs e)
{
this.FindOnChanged(resetChelTable);
}
private void dropFindButton_Click(object sender, EventArgs e)
{
findBox.Text = "";
this.FindOnChanged(null);
resetChelTable();
}
private void resetChelTable()
{
try
{
var tmp = FuncDB.ChelListTableMain(findBox.Text, showWorkerCheckBox.Checked);
var res = new List<string[]>();
this.ResetTable(
chelGridView,
tableColumns,
tmp
);
}
catch (Exception e) { this.ShowError(errorLabel, e.Message); }
}
private Chel selectedChel()
{
try
{
if (chelGridView.SelectedRows.Count != 1)
throw new Exception("Человек не выбран.");
if (int.TryParse((string)chelGridView.SelectedRows[0].Cells[0].Value, out int value))
return FuncDB.ChelGetById(value);
else
throw new Exception("Ошибка в таблице.");
}
catch (Exception e)
{
this.ShowError(errorLabel, e.Message);
return null;
}
}
public bool isCanceled = true;
public Chel formResult = null;
public ChelForm(bool select = false)
{
try
{
InitializeComponent();
selectButton.Visible = select;
menuStrip.Enabled = !select;
this.correctUpperMenu(menuStrip, 1);
resetChelTable();
addButton.Enabled =
changeButton.Enabled =
delButton.Enabled = false;
var user = this.GetUser();
if (user == null)
return;
delButton.Enabled = FuncDB.AccessGetByUserIdFormIdAccessId(user.Id, 1, 1) != null;
changeButton.Enabled = FuncDB.AccessGetByUserIdFormIdAccessId(user.Id, 1, 2) != null;
addButton.Enabled = FuncDB.AccessGetByUserIdFormIdAccessId(user.Id, 1, 3) != null;
}
catch { this.Close(); }
}
private void addButton_Click(object sender, EventArgs e)
{
var res = new SupportForms.WorkChelForm();
res.ShowDialog();
if (!res.isCanceled)
resetChelTable();
}
private void changeButton_Click(object sender, EventArgs e)
{
var chel = selectedChel();
if (chel == null)
return;
var res = new SupportForms.WorkChelForm(chel);
res.ShowDialog();
if (!res.isCanceled)
resetChelTable();
}
private void delButton_Click(object sender, EventArgs e)
{
var chel = selectedChel();
if (chel == null)
return;
try
{
FuncDB.ChelDelete(chel);
resetChelTable();
}
catch (Exception ex)
{
this.ShowError(errorLabel, ex.Message);
}
}
private void selectButton_Click(object sender, EventArgs e)
{
formResult = selectedChel();
isCanceled = false;
this.Close();
}
private void showWorker_CheckedChanged(object sender, EventArgs e)
{
resetChelTable();
}
private void upperMenuClicked(object sender, ToolStripItemClickedEventArgs e)
{
this.upperMenuClicked((MenuStrip)sender);
if (this.GetNextForm() != -1)
Close();
}
}
}