98 lines
2.4 KiB
C#
98 lines
2.4 KiB
C#
|
using Unity;
|
|||
|
|
|||
|
namespace LDBproject.AdditionalForms;
|
|||
|
|
|||
|
public partial class EmployeesF : Form
|
|||
|
{
|
|||
|
private readonly IUnityContainer _container;
|
|||
|
|
|||
|
public EmployeesF(IUnityContainer container)
|
|||
|
{
|
|||
|
InitializeComponent();
|
|||
|
_container = container ?? throw new ArgumentNullException(nameof(container));
|
|||
|
}
|
|||
|
|
|||
|
private void EmployeesF_Load(object sender, EventArgs e)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
ReloadList();
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
MessageBox.Show(ex.Message, "[ Error while saving ]", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void AddBtn_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
_container.Resolve<EmployeeF>().ShowDialog();
|
|||
|
ReloadList();
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
MessageBox.Show(ex.Message, "[ Error while adding element ]", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void UpdBtn_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
if (!GetiDFromRow(out var findID))
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
try
|
|||
|
{
|
|||
|
var form = _container.Resolve<EmployeeF>();
|
|||
|
form.ID = findID;
|
|||
|
form.ShowDialog();
|
|||
|
ReloadList();
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
MessageBox.Show(ex.Message, "[ Error while updating element ]", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void DelBtn_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
if (!GetiDFromRow(out var foundID))
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
if (MessageBox.Show("Remove element?", "Deleting", MessageBoxButtons.YesNo) != DialogResult.Yes)
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
try
|
|||
|
{
|
|||
|
ReloadList();
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
MessageBox.Show(ex.Message, "[ Error while removing element ]", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void ReloadList() { }
|
|||
|
|
|||
|
private bool GetiDFromRow(out int id)
|
|||
|
{
|
|||
|
id = 0;
|
|||
|
if (DataGV.SelectedRows.Count < 1)
|
|||
|
{
|
|||
|
MessageBox.Show("[ Error : element doesn't exist ]", "<ERROR>",
|
|||
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|||
|
}
|
|||
|
|
|||
|
id = Convert.ToInt32(DataGV.SelectedRows[0].Cells["CardID"].Value);
|
|||
|
return true;
|
|||
|
}
|
|||
|
}
|
|||
|
|