Diplom_O/MainForms/ChelForm.cs
2021-08-05 00:31:53 +05:00

188 lines
5.0 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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 Task errDrop;
private void ShowError(string msg = null)
{
errorLabel.Text = string.IsNullOrEmpty(msg) ? "Неизвестная ошибка." : msg;
errorLabel.Visible = true;
errDrop = new Task(() =>
{
var fd = errDrop.Id;
Task.Delay(5000).Wait();
if (errDrop.Id == fd)
if (InvokeRequired) Invoke((Action)(() => { errorLabel.Visible = false; }));
else errorLabel.Visible = false;
});
errDrop.Start();
}
private Task filterDrop;
private void findBox_TextChanged(object sender, EventArgs e)
{
filterDrop = new Task(() =>
{
var fd = filterDrop.Id;
Task.Delay(1000).Wait();
if (filterDrop.Id == fd)
if (InvokeRequired) Invoke((Action)(() => { resetChelTable(); }));
else resetChelTable();
});
filterDrop.Start();
}
private void dropFindButton_Click(object sender, EventArgs e)
{
findBox.Text = "";
filterDrop = new Task(() => { return; });
resetChelTable();
}
private void resetChelTable()
{
try
{
{
chelGridView.Rows.Clear();
chelGridView.Columns.Clear();
var c = chelGridView.Columns;
c.Add("Id", "№");
c.Add("FIO", "Фамилия И.О.");
c.Add("Male", "Пол");
c.Add("Birthday", "Дата рождения");
c.Add("Adress", "Адрес");
c.Add("INN", "ИНН");
c.Add("SNILS", "СНИЛС");
c.Add("Pasport", "Паспорт");
c[0].Width = 40;
c[1].Width = 120;
c[2].Width = 40;
c[3].Width = 80;
c[4].Width = 140;
c[5].Width = 90;
c[6].Width = 100;
c[7].Width = 140;
c[4].DefaultCellStyle.WrapMode = DataGridViewTriState.True;
c[7].DefaultCellStyle.WrapMode = DataGridViewTriState.True;
}
{
var arr = FuncDB.ListChel(findBox.Text);
var r = chelGridView.Rows;
foreach (var chel in arr)
if (showWorkerCheckBox.Checked || !FuncDB.HaveChelRabotnik(chel.Id))
r.Add(new object[] {
chel.Id,
chel.FName +
(string.IsNullOrEmpty(chel.SName) ? "" : (" " + chel.SName[0] + ".")) +
(string.IsNullOrEmpty(chel.TName) ? "" : (" " + chel.TName[0] + ".")),
chel.Male ? "Муж" : "Жен",
chel.Birthday.ToString("yyyy.MM.dd"),
chel.Address,
chel.INN,
chel.SNILS,
chel.Pasport
});
}
if (chelGridView.Rows.Count > 0)
chelGridView.Rows[0].Selected = true;
}
catch (Exception e) { ShowError(e.Message); }
}
private Chel selectedChel()
{
try
{
if (chelGridView.SelectedRows.Count != 1) throw new Exception("Человек не выбран.");
var chel = FuncDB.GetChel((int)chelGridView.SelectedRows[0].Cells[0].Value);
return chel;
}
catch (Exception e) { ShowError(e.Message); return null; }
}
public ChelForm()
{
try
{
InitializeComponent();
chelRodMI.Enabled = false;
resetChelTable();
}
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) { ShowError("Человек не выбран."); 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) { ShowError("Человек не выбран."); return; }
if (FuncDB.HaveChelToChel(chel.Id)) { ShowError("Человек есть в таблице родственников."); return; }
try
{
FuncDB.DelChel(chel);
resetChelTable();
}
catch (Exception ex) { ShowError(ex.Message); }
}
public void MI_Click(object sender, EventArgs e)
{
object form = null;
var idxMenu = -1;
try { idxMenu = menuStrip.Items.IndexOf((ToolStripMenuItem)sender); }
catch { };
switch (idxMenu)
{
case 0: form = new ShtatForm(); break;
case 1: form = new RabForm(); break;
case 2: form = new OtpForm(); break;
case 3: form = new ChelForm(); break;
}
if (form != null)
{
this.Hide();
((Form)form).Closed += (s, args) => this.Close();
((Form)form).Show();
return;
}
ShowError("Ошибка перехода на новую форму.");
}
private void checkBox_CheckedChanged(object sender, EventArgs e)
{
resetChelTable();
}
private Chel chelRod = null;
private void chelRodLabel_Clicked(object sender, LinkLabelLinkClickedEventArgs e)
{
var chelForm = new SupportForms.SelectChelForm();
chelForm.ShowDialog();
if(chelForm.isCanceled)
}
}
}