Diplom_O/SupportForms/LearnForm.cs
2024-09-20 06:53:52 +03:00

83 lines
1.8 KiB
C#
Raw Permalink 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 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();
}
}
}