криво косо

This commit is contained in:
frog24 2024-05-08 23:09:55 +04:00
parent 20f7ee8e83
commit 87391c25c1
17 changed files with 1125 additions and 6 deletions

View File

@ -47,11 +47,10 @@ namespace DepartmentStaffDatabase
public abstract void DeleteCourses();
//public abstract void CreateEmployee_Course(Employee_Course employee_course);
//public abstract void UpdateEmployee_Course(Employee_Course employee_course);
//public abstract void DeleteEmployee_Course(Employee_Course employee_course);
//public abstract Employee_Course GetEmployee_Course(int id);
//public abstract List<Employee_Course> GetEmployee_Courses();
//public abstract void DeleteEmployee_Courses();
public abstract void CreateEmployee_Course(Employee_Course employee_course);
public abstract void DeleteEmployee_Course(int empId, int courseId);
public abstract Employee_Course GetEmployee_Course(int empId, int courseId);
public abstract List<Employee_Course> GetEmployee_Courses();
public abstract void DeleteEmployee_Courses();
}
}

View File

@ -456,5 +456,67 @@ namespace DepartmentStaffDatabase
using var cmd = new NpgsqlCommand($"DELETE FROM course", conn);
cmd.ExecuteNonQuery();
}
//=======================================================================
public override void CreateEmployee_Course(Employee_Course employee_course)
{
using var conn = GetConnect();
conn.Open();
using var cmd = new NpgsqlCommand
("INSERT INTO employee_course VALUES (@EmployeeId, @CourseId)", conn);
cmd.Parameters.AddWithValue("@EmployeeId", employee_course.EmployeeId);
cmd.Parameters.AddWithValue("@CourseId", employee_course.CourseId);
cmd.ExecuteNonQuery();
}
public override void DeleteEmployee_Course(int empId, int courseId)
{
using var conn = GetConnect();
conn.Open();
using var cmd = new NpgsqlCommand($"DELETE FROM employee_course WHERE EmployeeId = @EmployeeId AND CourseId = @CourseId", conn);
cmd.Parameters.AddWithValue("@EmployeeId", empId);
cmd.Parameters.AddWithValue("@CourseId", courseId);
cmd.ExecuteNonQuery();
}
public override Employee_Course GetEmployee_Course(int empId, int courseId)
{
using var conn = GetConnect();
conn.Open();
using var cmd = new NpgsqlCommand($"SELECT * FROM employee_course WHERE EmployeeId = {empId} AND CourseId = {courseId}", conn);
using var reader = cmd.ExecuteReader();
if (reader.Read())
{
return new Employee_Course
{
EmployeeId = reader.GetInt32(0),
CourseId = reader.GetInt32(1),
};
}
return null;
}
public override List<Employee_Course> GetEmployee_Courses()
{
List<Employee_Course> employee_course = new List<Employee_Course>();
using var conn = GetConnect();
conn.Open();
using var cmd = new NpgsqlCommand("SELECT * FROM employee_course", conn);
using var reader = cmd.ExecuteReader();
while (reader.Read())
{
employee_course.Add(new Employee_Course
{
EmployeeId = reader.GetInt32(0),
CourseId = reader.GetInt32(1),
});
}
return employee_course;
}
public override void DeleteEmployee_Courses()
{
using var conn = GetConnect();
conn.Open();
using var cmd = new NpgsqlCommand($"DELETE FROM employee_course", conn);
cmd.ExecuteNonQuery();
}
}
}

View File

@ -0,0 +1,121 @@
namespace DepartmentStaffView
{
partial class FormCourse
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
dateTimePicker1 = new DateTimePicker();
textBoxDuration = new TextBox();
label4 = new Label();
label2 = new Label();
buttonCancel = new Button();
buttonSave = new Button();
SuspendLayout();
//
// dateTimePicker1
//
dateTimePicker1.Location = new Point(160, 3);
dateTimePicker1.Name = "dateTimePicker1";
dateTimePicker1.Size = new Size(259, 23);
dateTimePicker1.TabIndex = 37;
//
// textBoxDuration
//
textBoxDuration.Location = new Point(160, 44);
textBoxDuration.Margin = new Padding(3, 2, 3, 2);
textBoxDuration.Name = "textBoxDuration";
textBoxDuration.Size = new Size(259, 23);
textBoxDuration.TabIndex = 36;
//
// label4
//
label4.AutoSize = true;
label4.Location = new Point(12, 47);
label4.Name = "label4";
label4.Size = new Size(127, 15);
label4.TabIndex = 35;
label4.Text = "Длительность в часах";
//
// label2
//
label2.AutoSize = true;
label2.Location = new Point(12, 9);
label2.Name = "label2";
label2.Size = new Size(100, 15);
label2.TabIndex = 34;
label2.Text = "Дата проведения";
//
// buttonCancel
//
buttonCancel.Location = new Point(337, 88);
buttonCancel.Margin = new Padding(3, 2, 3, 2);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(82, 22);
buttonCancel.TabIndex = 33;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += buttonCancel_Click;
//
// buttonSave
//
buttonSave.Location = new Point(220, 88);
buttonSave.Margin = new Padding(3, 2, 3, 2);
buttonSave.Name = "buttonSave";
buttonSave.Size = new Size(82, 22);
buttonSave.TabIndex = 32;
buttonSave.Text = "Сохранить";
buttonSave.UseVisualStyleBackColor = true;
buttonSave.Click += buttonSave_Click;
//
// FormCourse
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(438, 137);
Controls.Add(dateTimePicker1);
Controls.Add(textBoxDuration);
Controls.Add(label4);
Controls.Add(label2);
Controls.Add(buttonCancel);
Controls.Add(buttonSave);
Name = "FormCourse";
Text = "FormCourse";
Load += FormCourse_Load;
ResumeLayout(false);
PerformLayout();
}
#endregion
private DateTimePicker dateTimePicker1;
private TextBox textBoxDuration;
private Label label4;
private Label label2;
private Button buttonCancel;
private Button buttonSave;
}
}

View File

@ -0,0 +1,87 @@
using DepartmentStaffDatabase;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics.Contracts;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace DepartmentStaffView
{
public partial class FormCourse : Form
{
private readonly Abstracts db;
public int? CourseId;
public FormCourse(Abstracts abstracts)
{
InitializeComponent();
db = abstracts;
}
private void buttonSave_Click(object sender, EventArgs e)
{
try
{
if (string.IsNullOrEmpty(textBoxDuration.Text))
{
MessageBox.Show("Заполните поля. Они все обязательные!");
return;
}
if (CourseId.HasValue)
{
db.UpdateCourse(new()
{
Id = CourseId.Value,
HoursNumber = int.Parse(textBoxDuration.Text),
DateOfEvent = dateTimePicker1.Value,
Result = db.GetCourse(CourseId.Value).Result,
});
}
else
{
db.CreateCourse(new()
{
HoursNumber = int.Parse(textBoxDuration.Text),
DateOfEvent = dateTimePicker1.Value,
Result = "В процессе"
});
}
DialogResult = DialogResult.OK;
Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void buttonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
private void LoadData()
{
try
{
if (CourseId.HasValue)
{
textBoxDuration.Text = db.GetCourse(CourseId.Value).HoursNumber.ToString();
dateTimePicker1.Value = db.GetCourse(CourseId.Value).DateOfEvent;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void FormCourse_Load(object sender, EventArgs e)
{
LoadData();
}
}
}

View File

@ -0,0 +1,60 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -0,0 +1,115 @@
namespace DepartmentStaffView
{
partial class FormCourses
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
buttonDelete = new Button();
buttonгUpdate = new Button();
buttonCreate = new Button();
dataGridView1 = new DataGridView();
buttonComplete = new Button();
((System.ComponentModel.ISupportInitialize)dataGridView1).BeginInit();
SuspendLayout();
//
// buttonDelete
//
buttonDelete.Location = new Point(530, 117);
buttonDelete.Name = "buttonDelete";
buttonDelete.Size = new Size(75, 23);
buttonDelete.TabIndex = 8;
buttonDelete.Text = "Удалить";
buttonDelete.UseVisualStyleBackColor = true;
buttonDelete.Click += buttonDelete_Click;
//
// buttonгUpdate
//
buttonгUpdate.Location = new Point(530, 61);
buttonгUpdate.Name = "buttonгUpdate";
buttonгUpdate.Size = new Size(75, 23);
buttonгUpdate.TabIndex = 7;
buttonгUpdate.Text = "Обновить";
buttonгUpdate.UseVisualStyleBackColor = true;
buttonгUpdate.Click += buttonUpdate_Click;
//
// buttonCreate
//
buttonCreate.Location = new Point(530, 12);
buttonCreate.Name = "buttonCreate";
buttonCreate.Size = new Size(75, 23);
buttonCreate.TabIndex = 6;
buttonCreate.Text = "Добавить";
buttonCreate.UseVisualStyleBackColor = true;
buttonCreate.Click += buttonCreate_Click;
//
// dataGridView1
//
dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView1.Location = new Point(12, 11);
dataGridView1.Margin = new Padding(3, 2, 3, 2);
dataGridView1.Name = "dataGridView1";
dataGridView1.RowHeadersWidth = 51;
dataGridView1.RowTemplate.Height = 29;
dataGridView1.Size = new Size(477, 320);
dataGridView1.TabIndex = 5;
//
// buttonComplete
//
buttonComplete.Location = new Point(530, 170);
buttonComplete.Name = "buttonComplete";
buttonComplete.Size = new Size(87, 23);
buttonComplete.TabIndex = 9;
buttonComplete.Text = "Завершить";
buttonComplete.UseVisualStyleBackColor = true;
buttonComplete.Click += buttonComplete_Click;
//
// FormCourses
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(629, 349);
Controls.Add(buttonComplete);
Controls.Add(buttonDelete);
Controls.Add(buttonгUpdate);
Controls.Add(buttonCreate);
Controls.Add(dataGridView1);
Name = "FormCourses";
Text = "FormCourses";
Load += FormCourses_Load;
((System.ComponentModel.ISupportInitialize)dataGridView1).EndInit();
ResumeLayout(false);
}
#endregion
private Button buttonDelete;
private Button buttonгUpdate;
private Button buttonCreate;
private DataGridView dataGridView1;
private Button buttonComplete;
}
}

View File

@ -0,0 +1,99 @@
using DepartmentStaffDatabase;
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 FormCourses : Form
{
private readonly Abstracts db;
public FormCourses(Abstracts abstracts)
{
InitializeComponent();
db = abstracts;
}
private void LoadData()
{
try
{
var list = db.GetCourses();
dataGridView1.DataSource = list;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void FormCourses_Load(object sender, EventArgs e)
{
LoadData();
}
private void buttonCreate_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormCourse));
if (service is FormCourse form)
{
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
private void buttonUpdate_Click(object sender, EventArgs e)
{
if (dataGridView1.SelectedRows.Count == 1)
{
int id = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells["Id"].Value);
var service = Program.ServiceProvider?.GetService(typeof(FormCourse));
if (service is FormCourse form)
{
form.CourseId = id;
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
}
private void buttonDelete_Click(object sender, EventArgs e)
{
if (dataGridView1.SelectedRows.Count == 1)
{
int id = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells["Id"].Value);
try
{
db.DeleteCourse(id);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
LoadData();
}
}
private void buttonComplete_Click(object sender, EventArgs e)
{
if (dataGridView1.SelectedRows.Count == 1)
{
int id = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells["Id"].Value);
db.UpdateCourse(new()
{
Id = id,
HoursNumber = db.GetCourse(id).HoursNumber,
DateOfEvent = db.GetCourse(id).DateOfEvent,
Result = "Завершен",
});
}
LoadData();
}
}
}

View File

@ -0,0 +1,60 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -0,0 +1,124 @@
namespace DepartmentStaffView
{
partial class FormEmployee_Course
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
buttonCancel = new Button();
buttonSave = new Button();
label1 = new Label();
comboBoxEmployee = new ComboBox();
label2 = new Label();
comboBoxCourse = new ComboBox();
SuspendLayout();
//
// buttonCancel
//
buttonCancel.Location = new Point(284, 90);
buttonCancel.Margin = new Padding(3, 2, 3, 2);
buttonCancel.Name = "buttonCancel";
buttonCancel.Size = new Size(82, 22);
buttonCancel.TabIndex = 24;
buttonCancel.Text = "Отмена";
buttonCancel.UseVisualStyleBackColor = true;
buttonCancel.Click += buttonCancel_Click;
//
// buttonSave
//
buttonSave.Location = new Point(167, 90);
buttonSave.Margin = new Padding(3, 2, 3, 2);
buttonSave.Name = "buttonSave";
buttonSave.Size = new Size(82, 22);
buttonSave.TabIndex = 23;
buttonSave.Text = "Сохранить";
buttonSave.UseVisualStyleBackColor = true;
buttonSave.Click += buttonSave_Click;
//
// label1
//
label1.AutoSize = true;
label1.Location = new Point(12, 9);
label1.Name = "label1";
label1.Size = new Size(66, 15);
label1.TabIndex = 22;
label1.Text = "Сотрудник";
//
// comboBoxEmployee
//
comboBoxEmployee.FormattingEnabled = true;
comboBoxEmployee.Location = new Point(98, 6);
comboBoxEmployee.Margin = new Padding(3, 2, 3, 2);
comboBoxEmployee.Name = "comboBoxEmployee";
comboBoxEmployee.Size = new Size(268, 23);
comboBoxEmployee.TabIndex = 21;
//
// label2
//
label2.AutoSize = true;
label2.Location = new Point(12, 52);
label2.Name = "label2";
label2.Size = new Size(33, 15);
label2.TabIndex = 26;
label2.Text = "Курс";
//
// comboBoxCourse
//
comboBoxCourse.FormattingEnabled = true;
comboBoxCourse.Location = new Point(98, 49);
comboBoxCourse.Margin = new Padding(3, 2, 3, 2);
comboBoxCourse.Name = "comboBoxCourse";
comboBoxCourse.Size = new Size(268, 23);
comboBoxCourse.TabIndex = 25;
//
// FormEmployee_Course
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(399, 130);
Controls.Add(label2);
Controls.Add(comboBoxCourse);
Controls.Add(buttonCancel);
Controls.Add(buttonSave);
Controls.Add(label1);
Controls.Add(comboBoxEmployee);
Name = "FormEmployee_Course";
Text = "FormEmployee_Course";
Load += FormEmployee_Course_Load;
ResumeLayout(false);
PerformLayout();
}
#endregion
private Button buttonCancel;
private Button buttonSave;
private Label label1;
private ComboBox comboBoxEmployee;
private Label label2;
private ComboBox comboBoxCourse;
}
}

View File

@ -0,0 +1,70 @@
using DepartmentStaffDatabase;
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 static System.Windows.Forms.VisualStyles.VisualStyleElement;
namespace DepartmentStaffView
{
public partial class FormEmployee_Course : Form
{
private readonly Abstracts db;
public FormEmployee_Course(Abstracts abstracts)
{
InitializeComponent();
db = abstracts;
}
private void buttonSave_Click(object sender, EventArgs e)
{
try
{
db.CreateEmployee_Course(new()
{
EmployeeId = (comboBoxEmployee.SelectedItem as Employee).Id,
CourseId = (comboBoxCourse.SelectedItem as Course).Id,
});
DialogResult = DialogResult.OK;
Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void buttonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
private void LoadData()
{
try
{
var emp = db.GetEmployees();
comboBoxEmployee.DataSource = emp;
comboBoxEmployee.DisplayMember = "EmployeeName";
comboBoxEmployee.ValueMember = "Id";
var courses = db.GetCourses();
comboBoxCourse.DataSource = courses;
comboBoxCourse.DisplayMember = "CourseName";
comboBoxCourse.ValueMember = "Id";
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void FormEmployee_Course_Load(object sender, EventArgs e)
{
LoadData();
}
}
}

View File

@ -0,0 +1,60 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -0,0 +1,89 @@
namespace DepartmentStaffView
{
partial class FormEmployee_Courses
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
buttonDelete = new Button();
buttonCreate = new Button();
dataGridView1 = new DataGridView();
((System.ComponentModel.ISupportInitialize)dataGridView1).BeginInit();
SuspendLayout();
//
// buttonDelete
//
buttonDelete.Location = new Point(530, 52);
buttonDelete.Name = "buttonDelete";
buttonDelete.Size = new Size(75, 23);
buttonDelete.TabIndex = 12;
buttonDelete.Text = "Удалить";
buttonDelete.UseVisualStyleBackColor = true;
buttonDelete.Click += buttonDelete_Click;
//
// buttonCreate
//
buttonCreate.Location = new Point(530, 12);
buttonCreate.Name = "buttonCreate";
buttonCreate.Size = new Size(75, 23);
buttonCreate.TabIndex = 10;
buttonCreate.Text = "Добавить";
buttonCreate.UseVisualStyleBackColor = true;
buttonCreate.Click += buttonCreate_Click;
//
// dataGridView1
//
dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dataGridView1.Location = new Point(12, 11);
dataGridView1.Margin = new Padding(3, 2, 3, 2);
dataGridView1.Name = "dataGridView1";
dataGridView1.RowHeadersWidth = 51;
dataGridView1.RowTemplate.Height = 29;
dataGridView1.Size = new Size(477, 320);
dataGridView1.TabIndex = 9;
//
// FormEmployee_Courses
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(635, 344);
Controls.Add(buttonDelete);
Controls.Add(buttonCreate);
Controls.Add(dataGridView1);
Name = "FormEmployee_Courses";
Text = "FormEmployee_Courses";
Load += FormEmployee_Courses_Load;
((System.ComponentModel.ISupportInitialize)dataGridView1).EndInit();
ResumeLayout(false);
}
#endregion
private Button buttonDelete;
private Button buttonCreate;
private DataGridView dataGridView1;
}
}

View File

@ -0,0 +1,67 @@
using DepartmentStaffDatabase;
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 FormEmployee_Courses : Form
{
private readonly Abstracts db;
public FormEmployee_Courses(Abstracts abstracts)
{
InitializeComponent();
db = abstracts;
}
private void LoadData()
{
try
{
var list = db.GetEmployee_Courses();
dataGridView1.DataSource = list;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void FormEmployee_Courses_Load(object sender, EventArgs e)
{
LoadData();
}
private void buttonCreate_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormEmployee_Course));
if (service is FormEmployee_Course form)
{
if (form.ShowDialog() == DialogResult.OK)
{
LoadData();
}
}
}
private void buttonDelete_Click(object sender, EventArgs e)
{
if (dataGridView1.SelectedRows.Count == 1)
{
int empId = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells["EmployeeId"].Value);
int courseId = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells["CourseId"].Value);
try
{
db.DeleteEmployee_Course(empId, courseId);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
LoadData();
}
}
}
}

View File

@ -0,0 +1,60 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -32,6 +32,8 @@
buttonPositions = new Button();
buttonEmployees = new Button();
buttonContracts = new Button();
buttonCourses = new Button();
buttonEmpCourse = new Button();
SuspendLayout();
//
// buttonDepartments
@ -74,11 +76,33 @@
buttonContracts.UseVisualStyleBackColor = true;
buttonContracts.Click += buttonContracts_Click;
//
// buttonCourses
//
buttonCourses.Location = new Point(12, 254);
buttonCourses.Name = "buttonCourses";
buttonCourses.Size = new Size(141, 44);
buttonCourses.TabIndex = 4;
buttonCourses.Text = "Курсы";
buttonCourses.UseVisualStyleBackColor = true;
buttonCourses.Click += buttonCourses_Click;
//
// buttonEmpCourse
//
buttonEmpCourse.Location = new Point(12, 315);
buttonEmpCourse.Name = "buttonEmpCourse";
buttonEmpCourse.Size = new Size(141, 44);
buttonEmpCourse.TabIndex = 5;
buttonEmpCourse.Text = "Записать на курсы";
buttonEmpCourse.UseVisualStyleBackColor = true;
buttonEmpCourse.Click += buttonEmployee_Courses_Click;
//
// FormMain
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(800, 450);
Controls.Add(buttonEmpCourse);
Controls.Add(buttonCourses);
Controls.Add(buttonContracts);
Controls.Add(buttonEmployees);
Controls.Add(buttonPositions);
@ -94,5 +118,7 @@
private Button buttonPositions;
private Button buttonEmployees;
private Button buttonContracts;
private Button buttonCourses;
private Button buttonEmpCourse;
}
}

View File

@ -51,5 +51,21 @@ namespace DepartmentStaffView
form.Show();
}
}
private void buttonCourses_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormCourses));
if (service is FormCourses form)
{
form.Show();
}
}
private void buttonEmployee_Courses_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormEmployee_Courses));
if (service is FormEmployee_Courses form)
{
form.Show();
}
}
}
}

View File

@ -28,6 +28,10 @@ namespace DepartmentStaffView
services.AddTransient<FormEmployee>();
services.AddTransient<FormContracts>();
services.AddTransient<FormContract>();
services.AddTransient<FormCourses>();
services.AddTransient<FormCourse>();
services.AddTransient<FormEmployee_Courses>();
services.AddTransient<FormEmployee_Course>();
}
}
}