Diplom_O/MainForms/ChelForm.cs

148 lines
3.7 KiB
C#
Raw Permalink Normal View History

2021-07-23 16:44:42 +05:00
using Diplom_O.DataBase;
using System;
2021-07-21 16:57:47 +05:00
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
{
2024-09-20 08:53:52 +05:00
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)
};
2021-07-23 16:44:42 +05:00
private void findBox_TextChanged(object sender, EventArgs e)
2021-07-21 16:57:47 +05:00
{
2024-09-20 08:53:52 +05:00
this.FindOnChanged(resetChelTable);
2021-07-23 16:44:42 +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-25 09:43:21 +05:00
resetChelTable();
2021-07-21 16:57:47 +05:00
}
2021-07-23 16:44:42 +05:00
private void resetChelTable()
2021-07-21 16:57:47 +05:00
{
2021-07-23 16:44:42 +05:00
try
{
2024-09-20 08:53:52 +05:00
var tmp = FuncDB.ChelListTableMain(findBox.Text, showWorkerCheckBox.Checked);
var res = new List<string[]>();
this.ResetTable(
chelGridView,
tableColumns,
tmp
);
2021-07-23 16:44:42 +05:00
}
2024-09-20 08:53:52 +05:00
catch (Exception e) { this.ShowError(errorLabel, e.Message); }
2021-07-23 16:44:42 +05:00
}
private Chel selectedChel()
{
try
{
2024-09-20 08:53:52 +05:00
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;
2021-07-23 16:44:42 +05:00
}
}
2024-09-20 08:53:52 +05:00
public bool isCanceled = true;
public Chel formResult = null;
public ChelForm(bool select = false)
2021-07-23 16:44:42 +05:00
{
try
{
InitializeComponent();
2024-09-20 08:53:52 +05:00
selectButton.Visible = select;
menuStrip.Enabled = !select;
this.correctUpperMenu(menuStrip, 1);
2021-07-23 16:44:42 +05:00
resetChelTable();
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, 1, 1) != null;
changeButton.Enabled = FuncDB.AccessGetByUserIdFormIdAccessId(user.Id, 1, 2) != null;
addButton.Enabled = FuncDB.AccessGetByUserIdFormIdAccessId(user.Id, 1, 3) != null;
2021-07-23 16:44:42 +05:00
}
catch { this.Close(); }
}
2021-07-21 16:57:47 +05:00
private void addButton_Click(object sender, EventArgs e)
{
2021-07-23 16:44:42 +05:00
var res = new SupportForms.WorkChelForm();
res.ShowDialog();
if (!res.isCanceled)
resetChelTable();
2021-07-21 16:57:47 +05:00
}
2021-07-23 16:44:42 +05:00
private void changeButton_Click(object sender, EventArgs e)
2021-07-21 16:57:47 +05:00
{
2021-07-23 16:44:42 +05:00
var chel = selectedChel();
2024-09-20 08:53:52 +05:00
if (chel == null)
return;
2021-07-23 16:44:42 +05:00
var res = new SupportForms.WorkChelForm(chel);
res.ShowDialog();
if (!res.isCanceled)
resetChelTable();
2021-07-21 16:57:47 +05:00
}
2021-07-23 16:44:42 +05:00
private void delButton_Click(object sender, EventArgs e)
2021-07-21 16:57:47 +05:00
{
2021-07-23 16:44:42 +05:00
var chel = selectedChel();
2024-09-20 08:53:52 +05:00
if (chel == null)
return;
2021-07-23 16:44:42 +05:00
try
{
2024-09-20 08:53:52 +05:00
FuncDB.ChelDelete(chel);
2021-07-23 16:44:42 +05:00
resetChelTable();
}
2024-09-20 08:53:52 +05:00
catch (Exception ex)
2021-07-23 16:44:42 +05:00
{
2024-09-20 08:53:52 +05:00
this.ShowError(errorLabel, ex.Message);
2021-07-23 16:44:42 +05:00
}
}
2024-09-20 08:53:52 +05:00
private void selectButton_Click(object sender, EventArgs e)
{
formResult = selectedChel();
isCanceled = false;
this.Close();
}
private void showWorker_CheckedChanged(object sender, EventArgs e)
2021-07-23 16:44:42 +05:00
{
resetChelTable();
2021-07-21 16:57:47 +05:00
}
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-08-05 00:31:53 +05:00
}
2021-07-21 16:57:47 +05:00
}