284 lines
7.4 KiB
C#
284 lines
7.4 KiB
C#
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Threading.Tasks;
|
|||
|
using System.Windows.Forms;
|
|||
|
using Diplom_O.DataBase;
|
|||
|
|
|||
|
namespace Diplom_O
|
|||
|
{
|
|||
|
public static class FormExtention
|
|||
|
{
|
|||
|
public static User user = null;
|
|||
|
public static User GetUser(this Form form)
|
|||
|
{
|
|||
|
return user;
|
|||
|
}
|
|||
|
public static void SetUser(this Form form, User usr)
|
|||
|
{
|
|||
|
user = usr;
|
|||
|
}
|
|||
|
|
|||
|
public static int nextForm = -1;
|
|||
|
public static int GetNextForm(this Form form)
|
|||
|
{
|
|||
|
return nextForm;
|
|||
|
}
|
|||
|
public static void SetNextForm(this Form form, int value)
|
|||
|
{
|
|||
|
nextForm = value;
|
|||
|
}
|
|||
|
|
|||
|
public static void correctUpperMenu(this Form form, MenuStrip upMenu, int value)
|
|||
|
{
|
|||
|
var items = upMenu.Items;
|
|||
|
for (var i = 0; i < items.Count; i++)
|
|||
|
{
|
|||
|
if (user == null)
|
|||
|
{
|
|||
|
items[i].Enabled = false;
|
|||
|
continue;
|
|||
|
}
|
|||
|
var access = FuncDB.AccessGetByUserIdFormIdAccessId(user.Id, i, 0);
|
|||
|
if (access == null)
|
|||
|
{
|
|||
|
items[i].Enabled = false;
|
|||
|
continue;
|
|||
|
}
|
|||
|
items[i].Enabled = (i != value);
|
|||
|
}
|
|||
|
}
|
|||
|
public static void upperMenuClicked(this Form form, MenuStrip upMenu)
|
|||
|
{
|
|||
|
var menuItems = upMenu.Items;
|
|||
|
for (var i = 0; i < menuItems.Count; i++)
|
|||
|
if (menuItems[i].Selected)
|
|||
|
nextForm = i;
|
|||
|
}
|
|||
|
|
|||
|
private static int countErr = 0;
|
|||
|
private static int currTurnErr = 0;
|
|||
|
private static bool flagfollow = false;
|
|||
|
public static async void ShowError(this Form form, ToolStripStatusLabel errorLabel, string msg = null)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
int ticket = countErr;
|
|||
|
countErr = (countErr == int.MaxValue) ? 0 : countErr + 1;
|
|||
|
while (flagfollow && (currTurnErr != ticket))
|
|||
|
await Task.Delay(1000);
|
|||
|
Action func = () =>
|
|||
|
{
|
|||
|
errorLabel.Text = string.IsNullOrEmpty(msg) ? "Неизвестная ошибка." : msg;
|
|||
|
errorLabel.Visible = true;
|
|||
|
};
|
|||
|
if (form.InvokeRequired)
|
|||
|
form.Invoke(func);
|
|||
|
else
|
|||
|
func.Invoke();
|
|||
|
await Task.Delay(5000);
|
|||
|
func = () =>
|
|||
|
{
|
|||
|
errorLabel.Visible = false;
|
|||
|
};
|
|||
|
if (currTurnErr == ticket)
|
|||
|
if (form.InvokeRequired)
|
|||
|
form.Invoke(func);
|
|||
|
else
|
|||
|
func.Invoke();
|
|||
|
}
|
|||
|
catch
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
finally
|
|||
|
{
|
|||
|
currTurnErr = (currTurnErr == int.MaxValue) ? 0 : currTurnErr + 1;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private static int countFind = 0;
|
|||
|
public delegate void resetTableFind();
|
|||
|
public static async void FindOnChanged(this Form form, resetTableFind func)
|
|||
|
{
|
|||
|
var flag = ++countFind;
|
|||
|
await Task.Delay(1000);
|
|||
|
Action lFunc = () =>
|
|||
|
{
|
|||
|
func?.Invoke();
|
|||
|
};
|
|||
|
if (flag == countFind)
|
|||
|
if (form.InvokeRequired)
|
|||
|
form.Invoke(lFunc);
|
|||
|
else
|
|||
|
lFunc.Invoke();
|
|||
|
}
|
|||
|
|
|||
|
public static async void ResetTable(this Form form, DataGridView table, ColumnConf[] columns, string[][] data)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
var currSelected = new List<(int col, int row)>();
|
|||
|
var tmpCells = table.SelectedCells;
|
|||
|
for (var i = 0; i < tmpCells.Count; i++)
|
|||
|
currSelected.Add((
|
|||
|
tmpCells[i].ColumnIndex,
|
|||
|
tmpCells[i].RowIndex
|
|||
|
));
|
|||
|
ClearTable(form, table, columns);
|
|||
|
FillTable(form, table, data);
|
|||
|
for (var i = currSelected.Count - 1; i >= 0; i--)
|
|||
|
{
|
|||
|
var col = currSelected[i].col;
|
|||
|
var row = currSelected[i].row;
|
|||
|
if (row >= 0 && row < table.Rows.Count && col >= 0 && col < table.Columns.Count)
|
|||
|
table[col, row].Selected = true;
|
|||
|
}
|
|||
|
}
|
|||
|
catch
|
|||
|
{
|
|||
|
throw;
|
|||
|
await Task.Delay(1000);
|
|||
|
}
|
|||
|
}
|
|||
|
public static async void ClearTable(this Form form, DataGridView table, ColumnConf[] columns)
|
|||
|
{
|
|||
|
Action func = () =>
|
|||
|
{
|
|||
|
table.Rows.Clear();
|
|||
|
table.Columns.Clear();
|
|||
|
var c = table.Columns;
|
|||
|
for (var i = 0; i < columns.Length; i++)
|
|||
|
{
|
|||
|
c.Add(columns[i].name, columns[i].name);
|
|||
|
c[i].Width = columns[i].size;
|
|||
|
if (columns[i].warp)
|
|||
|
c[i].DefaultCellStyle.WrapMode = DataGridViewTriState.True;
|
|||
|
}
|
|||
|
};
|
|||
|
if (form.InvokeRequired)
|
|||
|
form.Invoke(func);
|
|||
|
else
|
|||
|
func.Invoke();
|
|||
|
return;
|
|||
|
await Task.Delay(1000);
|
|||
|
}
|
|||
|
public static async void FillTable(this Form form, DataGridView table, string[][] data)
|
|||
|
{
|
|||
|
if (data == null || data.Length == 0)
|
|||
|
return;
|
|||
|
try
|
|||
|
{
|
|||
|
if (table.Columns.Count != data[0].Length)
|
|||
|
throw new Exception("Количество элементов данных (" + data[0].Length +
|
|||
|
") не соответствует колчиству столбцов (" + table.Columns.Count + ")");
|
|||
|
foreach (var lRow in data)
|
|||
|
table.Rows.Add(lRow);
|
|||
|
}
|
|||
|
catch
|
|||
|
{
|
|||
|
throw;
|
|||
|
await Task.Delay(1000);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
public static class FormArray
|
|||
|
{
|
|||
|
public static readonly string[] formName = {
|
|||
|
"Актуальные вакансии",
|
|||
|
"Люди",
|
|||
|
"Сотрудники",
|
|||
|
"Стаж",
|
|||
|
"Образование",
|
|||
|
"Отпуск/Больничный",
|
|||
|
"Дети",
|
|||
|
"Настройки"
|
|||
|
};
|
|||
|
public static readonly string[] formAccess = {
|
|||
|
"Чтение",
|
|||
|
"Удаление",
|
|||
|
"Изменение",
|
|||
|
"Добавление"
|
|||
|
};
|
|||
|
|
|||
|
public static int GetNameInt(string name)
|
|||
|
{
|
|||
|
var result = -1;
|
|||
|
for (var i = 0; i < formName.Length; i++)
|
|||
|
if (name.CompareTo(formName[i]) == 0)
|
|||
|
result = i;
|
|||
|
return result;
|
|||
|
}
|
|||
|
public static string GetNameString(int id)
|
|||
|
{
|
|||
|
var result = "Ошибка";
|
|||
|
if (id >= 0 && id < formName.Length)
|
|||
|
result = formName[id];
|
|||
|
return result;
|
|||
|
}
|
|||
|
public static int GetAccessInt(string name)
|
|||
|
{
|
|||
|
var result = -1;
|
|||
|
for (var i = 0; i < formAccess.Length; i++)
|
|||
|
if (name.CompareTo(formAccess[i]) == 0)
|
|||
|
result = i;
|
|||
|
return result;
|
|||
|
}
|
|||
|
public static string GetAccessString(int id)
|
|||
|
{
|
|||
|
var result = "Ошибка";
|
|||
|
if (id >= 0 && id < formAccess.Length)
|
|||
|
result = formAccess[id];
|
|||
|
return result;
|
|||
|
}
|
|||
|
}
|
|||
|
public static class TableColumnssss
|
|||
|
{
|
|||
|
public static readonly ColumnConf Id = new ColumnConf(name: "№");
|
|||
|
public static readonly ColumnConf Free = new ColumnConf(name: "Своб.");
|
|||
|
public static readonly ColumnConf KolVo = new ColumnConf(name: "Кол-во");
|
|||
|
public static readonly ColumnConf Male = new ColumnConf(name: "Пол");
|
|||
|
|
|||
|
public static readonly ColumnConf TabNum = new ColumnConf(name: "Таб. №", size: 80);
|
|||
|
public static readonly ColumnConf BDay = new ColumnConf(name: "Дата рождения", size: 80);
|
|||
|
public static readonly ColumnConf INN = new ColumnConf(name: "ИНН", size: 100);
|
|||
|
public static readonly ColumnConf SNILS = new ColumnConf(name: "СНИЛС", size: 100);
|
|||
|
public static readonly ColumnConf Dolj = new ColumnConf(name: "Должность", size: 140);
|
|||
|
public static readonly ColumnConf TypeStaj = new ColumnConf(name: "Тип стажа", size: 140);
|
|||
|
public static readonly ColumnConf FIO = new ColumnConf(name: "Фамилия И.О.", size: 140);
|
|||
|
|
|||
|
public static readonly ColumnConf Adress = new ColumnConf(name: "Адрес", size: 140, warp: true);
|
|||
|
public static readonly ColumnConf Pasport = new ColumnConf(name: "Паспорт", size: 140, warp: true);
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
public struct ColumnConf
|
|||
|
{
|
|||
|
public string name;
|
|||
|
public int size;
|
|||
|
public bool warp;
|
|||
|
public ColumnConf(string name = "ErNO", int size = 60, bool warp = false)
|
|||
|
{
|
|||
|
this.name = name;
|
|||
|
this.size = size;
|
|||
|
this.warp = warp;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public struct CopyOfColumnConf
|
|||
|
{
|
|||
|
public string name;
|
|||
|
public int size;
|
|||
|
public bool warp;
|
|||
|
public CopyOfColumnConf(string name = "ErNO", int size = 60, bool warp = false)
|
|||
|
{
|
|||
|
this.name = name;
|
|||
|
this.size = size;
|
|||
|
this.warp = warp;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
}
|