66 lines
1.9 KiB
C#

using DepartmentStaffDatabase;
using Microsoft.VisualBasic.ApplicationServices;
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 DepartmentStaffView
{
public partial class FormDepartment : Form
{
public int? DepartmentId { get; set; }
private readonly Abstracts db;
public FormDepartment(Abstracts abstracts)
{
InitializeComponent();
db = abstracts;
}
private void buttonSave_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(textBox1.Text) || string.IsNullOrEmpty(textBox2.Text))
{
MessageBox.Show("Заполните поля. Они все обязательные!");
return;
}
if (DepartmentId.HasValue)
{
db.UpdateDepartment(new()
{
Id = DepartmentId.Value,
DepartmentName = textBox1.Text,
Head = textBox2.Text,
});
}
else
{
db.CreateDepartment(new()
{
DepartmentName = textBox1.Text,
Head = textBox2.Text,
});
}
DialogResult = DialogResult.OK;
}
private void buttonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
private void FormDepartment_Load(object sender, EventArgs e)
{
if (DepartmentId.HasValue)
{
var dep = db.GetDepartment(DepartmentId.Value);
textBox1.Text = dep.DepartmentName;
textBox2.Text = dep.Head;
}
}
}
}