Diplom_O/SupportForms/LearnForm.cs

83 lines
1.8 KiB
C#
Raw Permalink Normal View History

2024-09-20 08:53:52 +05:00
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;
using Diplom_O.DataBase;
namespace Diplom_O.SupportForms
{
public partial class LearnForm : Form
{
public bool isCanceled = false;
private int chelId = 0;
private Learn learn = null;
public LearnForm(Learn learn = null, int? chelId = null)
{
InitializeComponent();
if (learn == null && chelId == null)
throw new Exception("Не выбран сотрудник.");
dateBox.Value = DateTime.Now;
try
{
if (learn != null)
{
this.learn = learn;
this.chelId = learn.ChelId;
nameBox.Text = learn.NameSchool;
typeBox.Text = learn.Type;
specBox.Text = learn.Spec;
dateBox.Value = learn.End;
workButton.Text = "Изменить";
}
else
{
this.chelId = chelId.Value;
}
}
catch (Exception e)
{
this.ShowError(errorLabel, e.Message);
workButton.Enabled = false;
}
}
private void workButton_Click(object sender, EventArgs e)
{
try
{
var _learn = new Learn();
_learn.NameSchool = nameBox.Text;
_learn.Type = typeBox.Text;
_learn.Spec = specBox.Text;
_learn.Curs = textBox1.Text;
_learn.ProfPer = textBox2.Text;
_learn.ChelId = chelId;
_learn.End = dateBox.Value;
FuncDB.LearnCheckValid(_learn);
if (learn == null)
FuncDB.LearnAdd(_learn);
else
{
_learn.Id = learn.Id;
FuncDB.LearnChange(_learn);
}
this.Close();
}
catch (Exception ex)
{
this.ShowError(errorLabel, ex.Message);
}
}
private void canceledButton_Click(object sender, EventArgs e)
{
isCanceled = true;
this.Close();
}
}
}