+ еще одна сущность, но дефолтные значения почему-то не работают
+ фиксы всякие разные
This commit is contained in:
parent
4be071175e
commit
796a659d3f
@ -24,13 +24,13 @@ namespace DepartmentStaffDatabase
|
|||||||
public abstract List<Position> GetPositions();
|
public abstract List<Position> GetPositions();
|
||||||
public abstract void Deletepositions();
|
public abstract void Deletepositions();
|
||||||
|
|
||||||
//public abstract void CreateEmployee(Employee employee);
|
public abstract void CreateEmployee(Employee employee);
|
||||||
//public abstract void UpdateEmployee(Employee employee);
|
public abstract void UpdateEmployee(Employee employee);
|
||||||
//public abstract void DeleteEmployee(int id);
|
public abstract void DeleteEmployee(int id);
|
||||||
//public abstract Employee GetEmployee(int id);
|
public abstract Employee GetEmployee(int id);
|
||||||
//public abstract Employee GetEmployee(string employeeName);
|
public abstract Employee GetEmployee(string employeeName);
|
||||||
//public abstract List<Employee> GetEmployees();
|
public abstract List<Employee> GetEmployees();
|
||||||
//public abstract void DeleteEmployees();
|
public abstract void DeleteEmployees();
|
||||||
|
|
||||||
//public abstract void CreateContract(Contract contract);
|
//public abstract void CreateContract(Contract contract);
|
||||||
//public abstract void UpdateContract(Contract contract);
|
//public abstract void UpdateContract(Contract contract);
|
||||||
|
@ -196,34 +196,112 @@ namespace DepartmentStaffDatabase
|
|||||||
|
|
||||||
//=======================================================================
|
//=======================================================================
|
||||||
|
|
||||||
//public override void CreateEmployee(Employee employee)
|
public override void CreateEmployee(Employee employee)
|
||||||
//{
|
{
|
||||||
// using var conn = GetConnect();
|
using var conn = GetConnect();
|
||||||
// conn.Open();
|
conn.Open();
|
||||||
// using var cmd = new NpgsqlCommand
|
using var cmd = new NpgsqlCommand
|
||||||
// ("INSERT INTO employee VALUES (nextval('Employee_seq'), @Name, @Birthdate, @Address, @PhoneNumber, @Email, @PositionId)", conn);
|
("INSERT INTO employee VALUES (nextval('Employee_seq'), @Name, @Birthdate, @Address, @PhoneNumber, @Email, @PositionId)", conn);
|
||||||
// cmd.Parameters.AddWithValue("@name", employee.EmployeeName);
|
cmd.Parameters.AddWithValue("@name", employee.EmployeeName);
|
||||||
// cmd.Parameters.AddWithValue("@Birthdate", employee.Birthdate);
|
cmd.Parameters.AddWithValue("@Birthdate", employee.Birthdate);
|
||||||
// cmd.Parameters.AddWithValue("@Address", employee.Address);
|
cmd.Parameters.AddWithValue("@Address", employee.Address);
|
||||||
// cmd.Parameters.AddWithValue("@PhoneNumber", employee.PhoneNumber);
|
cmd.Parameters.AddWithValue("@PhoneNumber", employee.PhoneNumber);
|
||||||
// cmd.Parameters.AddWithValue("@Email", employee.Email);
|
cmd.Parameters.AddWithValue("@Email", employee.Email);
|
||||||
// cmd.Parameters.AddWithValue("@PositionId", employee.PositionId);
|
cmd.Parameters.AddWithValue("@PositionId", employee.PositionId);
|
||||||
// cmd.ExecuteNonQuery();
|
cmd.ExecuteNonQuery();
|
||||||
//}
|
}
|
||||||
//public override void UpdateEmployee(Employee employee)
|
public override void UpdateEmployee(Employee employee)
|
||||||
//{
|
{
|
||||||
// using var conn = GetConnect();
|
using var conn = GetConnect();
|
||||||
// conn.Open();
|
conn.Open();
|
||||||
// using var cmd = new NpgsqlCommand($"UPDATE employee SET name = @name, salary = @salary, departmentId = @departmentId WHERE id = @Id", conn);
|
using var cmd = new NpgsqlCommand($"UPDATE employee SET name = @name, birthdate = @birthdate, " +
|
||||||
// cmd.Parameters.AddWithValue("@name", position.PositionName);
|
$"address = @address, phoneNumber = @phoneNumber, email = @email, positionId = @positionId WHERE id = @Id", conn);
|
||||||
// cmd.Parameters.AddWithValue("@salary", position.Salary);
|
cmd.Parameters.AddWithValue("@name", employee.EmployeeName);
|
||||||
// cmd.Parameters.AddWithValue("@departmentId", position.DepartmentId);
|
cmd.Parameters.AddWithValue("@Birthdate", employee.Birthdate);
|
||||||
// cmd.ExecuteNonQuery();
|
cmd.Parameters.AddWithValue("@Address", employee.Address);
|
||||||
//}
|
cmd.Parameters.AddWithValue("@PhoneNumber", employee.PhoneNumber);
|
||||||
//public override void DeleteEmployee(int id);
|
cmd.Parameters.AddWithValue("@Email", employee.Email);
|
||||||
//public override Employee GetEmployee(int id);
|
cmd.Parameters.AddWithValue("@PositionId", employee.PositionId);
|
||||||
//public override Employee GetEmployee(string employeeName);
|
cmd.ExecuteNonQuery();
|
||||||
//public override List<Employee> GetEmployees();
|
}
|
||||||
//public override void DeleteEmployees();
|
public override void DeleteEmployee(int id)
|
||||||
|
{
|
||||||
|
using var conn = GetConnect();
|
||||||
|
conn.Open();
|
||||||
|
using var cmd = new NpgsqlCommand($"DELETE FROM employee WHERE id = @Id", conn);
|
||||||
|
cmd.Parameters.AddWithValue("@Id", id);
|
||||||
|
cmd.ExecuteNonQuery();
|
||||||
|
}
|
||||||
|
public override Employee GetEmployee(int id)
|
||||||
|
{
|
||||||
|
using var conn = GetConnect();
|
||||||
|
conn.Open();
|
||||||
|
using var cmd = new NpgsqlCommand($"SELECT * FROM employee WHERE id = {id}", conn);
|
||||||
|
using var reader = cmd.ExecuteReader();
|
||||||
|
if (reader.Read())
|
||||||
|
{
|
||||||
|
return new Employee
|
||||||
|
{
|
||||||
|
Id = reader.GetInt32(0),
|
||||||
|
EmployeeName = reader.GetString(1),
|
||||||
|
Birthdate = reader.GetDateTime(2),
|
||||||
|
Address = reader.GetString(3),
|
||||||
|
PhoneNumber = reader.GetString(4),
|
||||||
|
Email = reader.GetString(5),
|
||||||
|
PositionId = reader.GetInt32(6),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public override Employee GetEmployee(string employeeName)
|
||||||
|
{
|
||||||
|
using var conn = GetConnect();
|
||||||
|
conn.Open();
|
||||||
|
using var cmd = new NpgsqlCommand($"SELECT * FROM employee WHERE id = {employeeName}", conn);
|
||||||
|
using var reader = cmd.ExecuteReader();
|
||||||
|
if (reader.Read())
|
||||||
|
{
|
||||||
|
return new Employee
|
||||||
|
{
|
||||||
|
Id = reader.GetInt32(0),
|
||||||
|
EmployeeName = reader.GetString(1),
|
||||||
|
Birthdate = reader.GetDateTime(2),
|
||||||
|
Address = reader.GetString(3),
|
||||||
|
PhoneNumber = reader.GetString(4),
|
||||||
|
Email = reader.GetString(5),
|
||||||
|
PositionId = reader.GetInt32(6),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public override List<Employee> GetEmployees()
|
||||||
|
{
|
||||||
|
List<Employee> employees = new List<Employee>();
|
||||||
|
using var conn = GetConnect();
|
||||||
|
conn.Open();
|
||||||
|
using var cmd = new NpgsqlCommand("SELECT * FROM employee", conn);
|
||||||
|
using var reader = cmd.ExecuteReader();
|
||||||
|
while (reader.Read())
|
||||||
|
{
|
||||||
|
employees.Add(new Employee
|
||||||
|
{
|
||||||
|
Id = reader.GetInt32(0),
|
||||||
|
EmployeeName = reader.GetString(1),
|
||||||
|
Birthdate = reader.GetDateTime(2),
|
||||||
|
Address = reader.GetString(3),
|
||||||
|
PhoneNumber = reader.GetString(4),
|
||||||
|
Email = reader.GetString(5),
|
||||||
|
PositionId = reader.GetInt32(6),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return employees;
|
||||||
|
}
|
||||||
|
public override void DeleteEmployees()
|
||||||
|
{
|
||||||
|
using var conn = GetConnect();
|
||||||
|
conn.Open();
|
||||||
|
using var cmd = new NpgsqlCommand($"DELETE FROM employee", conn);
|
||||||
|
cmd.ExecuteNonQuery();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
214
DepartmentStaffView/DepartmentStaffView/FormEmployee.Designer.cs
generated
Normal file
214
DepartmentStaffView/DepartmentStaffView/FormEmployee.Designer.cs
generated
Normal file
@ -0,0 +1,214 @@
|
|||||||
|
namespace DepartmentStaffView
|
||||||
|
{
|
||||||
|
partial class FormEmployee
|
||||||
|
{
|
||||||
|
/// <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()
|
||||||
|
{
|
||||||
|
textBoxEmail = new TextBox();
|
||||||
|
label4 = new Label();
|
||||||
|
textBoxName = new TextBox();
|
||||||
|
label2 = new Label();
|
||||||
|
buttonCancel = new Button();
|
||||||
|
buttonSave = new Button();
|
||||||
|
label1 = new Label();
|
||||||
|
comboBoxPosition = new ComboBox();
|
||||||
|
label3 = new Label();
|
||||||
|
dateTimePicker1 = new DateTimePicker();
|
||||||
|
textBoxAddress = new TextBox();
|
||||||
|
label5 = new Label();
|
||||||
|
textBoxPhone = new TextBox();
|
||||||
|
label6 = new Label();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// textBoxEmail
|
||||||
|
//
|
||||||
|
textBoxEmail.Location = new Point(151, 194);
|
||||||
|
textBoxEmail.Margin = new Padding(3, 2, 3, 2);
|
||||||
|
textBoxEmail.Name = "textBoxEmail";
|
||||||
|
textBoxEmail.Size = new Size(268, 23);
|
||||||
|
textBoxEmail.TabIndex = 28;
|
||||||
|
//
|
||||||
|
// label4
|
||||||
|
//
|
||||||
|
label4.AutoSize = true;
|
||||||
|
label4.Location = new Point(12, 197);
|
||||||
|
label4.Name = "label4";
|
||||||
|
label4.Size = new Size(59, 15);
|
||||||
|
label4.TabIndex = 27;
|
||||||
|
label4.Text = "Эл. почта";
|
||||||
|
//
|
||||||
|
// textBoxName
|
||||||
|
//
|
||||||
|
textBoxName.Location = new Point(151, 44);
|
||||||
|
textBoxName.Margin = new Padding(3, 2, 3, 2);
|
||||||
|
textBoxName.Name = "textBoxName";
|
||||||
|
textBoxName.Size = new Size(268, 23);
|
||||||
|
textBoxName.TabIndex = 26;
|
||||||
|
//
|
||||||
|
// label2
|
||||||
|
//
|
||||||
|
label2.AutoSize = true;
|
||||||
|
label2.Location = new Point(12, 47);
|
||||||
|
label2.Name = "label2";
|
||||||
|
label2.Size = new Size(97, 15);
|
||||||
|
label2.TabIndex = 25;
|
||||||
|
label2.Text = "Имя сотрудника";
|
||||||
|
//
|
||||||
|
// buttonCancel
|
||||||
|
//
|
||||||
|
buttonCancel.Location = new Point(336, 237);
|
||||||
|
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(219, 237);
|
||||||
|
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(69, 15);
|
||||||
|
label1.TabIndex = 22;
|
||||||
|
label1.Text = "Должность";
|
||||||
|
//
|
||||||
|
// comboBoxPosition
|
||||||
|
//
|
||||||
|
comboBoxPosition.FormattingEnabled = true;
|
||||||
|
comboBoxPosition.Location = new Point(151, 7);
|
||||||
|
comboBoxPosition.Margin = new Padding(3, 2, 3, 2);
|
||||||
|
comboBoxPosition.Name = "comboBoxPosition";
|
||||||
|
comboBoxPosition.Size = new Size(268, 23);
|
||||||
|
comboBoxPosition.TabIndex = 21;
|
||||||
|
//
|
||||||
|
// label3
|
||||||
|
//
|
||||||
|
label3.AutoSize = true;
|
||||||
|
label3.Location = new Point(12, 85);
|
||||||
|
label3.Name = "label3";
|
||||||
|
label3.Size = new Size(90, 15);
|
||||||
|
label3.TabIndex = 29;
|
||||||
|
label3.Text = "Дата рождения";
|
||||||
|
//
|
||||||
|
// dateTimePicker1
|
||||||
|
//
|
||||||
|
dateTimePicker1.Location = new Point(151, 79);
|
||||||
|
dateTimePicker1.Name = "dateTimePicker1";
|
||||||
|
dateTimePicker1.Size = new Size(200, 23);
|
||||||
|
dateTimePicker1.TabIndex = 30;
|
||||||
|
//
|
||||||
|
// textBoxAddress
|
||||||
|
//
|
||||||
|
textBoxAddress.Location = new Point(151, 116);
|
||||||
|
textBoxAddress.Margin = new Padding(3, 2, 3, 2);
|
||||||
|
textBoxAddress.Name = "textBoxAddress";
|
||||||
|
textBoxAddress.Size = new Size(268, 23);
|
||||||
|
textBoxAddress.TabIndex = 32;
|
||||||
|
//
|
||||||
|
// label5
|
||||||
|
//
|
||||||
|
label5.AutoSize = true;
|
||||||
|
label5.Location = new Point(12, 119);
|
||||||
|
label5.Name = "label5";
|
||||||
|
label5.Size = new Size(40, 15);
|
||||||
|
label5.TabIndex = 31;
|
||||||
|
label5.Text = "Адрес";
|
||||||
|
//
|
||||||
|
// textBoxPhone
|
||||||
|
//
|
||||||
|
textBoxPhone.Location = new Point(151, 156);
|
||||||
|
textBoxPhone.Margin = new Padding(3, 2, 3, 2);
|
||||||
|
textBoxPhone.Name = "textBoxPhone";
|
||||||
|
textBoxPhone.Size = new Size(268, 23);
|
||||||
|
textBoxPhone.TabIndex = 34;
|
||||||
|
//
|
||||||
|
// label6
|
||||||
|
//
|
||||||
|
label6.AutoSize = true;
|
||||||
|
label6.Location = new Point(12, 159);
|
||||||
|
label6.Name = "label6";
|
||||||
|
label6.Size = new Size(55, 15);
|
||||||
|
label6.TabIndex = 33;
|
||||||
|
label6.Text = "Телефон";
|
||||||
|
//
|
||||||
|
// FormEmployee
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(472, 290);
|
||||||
|
Controls.Add(textBoxPhone);
|
||||||
|
Controls.Add(label6);
|
||||||
|
Controls.Add(textBoxAddress);
|
||||||
|
Controls.Add(label5);
|
||||||
|
Controls.Add(dateTimePicker1);
|
||||||
|
Controls.Add(label3);
|
||||||
|
Controls.Add(textBoxEmail);
|
||||||
|
Controls.Add(label4);
|
||||||
|
Controls.Add(textBoxName);
|
||||||
|
Controls.Add(label2);
|
||||||
|
Controls.Add(buttonCancel);
|
||||||
|
Controls.Add(buttonSave);
|
||||||
|
Controls.Add(label1);
|
||||||
|
Controls.Add(comboBoxPosition);
|
||||||
|
Name = "FormEmployee";
|
||||||
|
Text = "FormEmployee";
|
||||||
|
Load += FormEmployee_Load;
|
||||||
|
ResumeLayout(false);
|
||||||
|
PerformLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private TextBox textBoxEmail;
|
||||||
|
private Label label4;
|
||||||
|
private TextBox textBoxName;
|
||||||
|
private Label label2;
|
||||||
|
private Button buttonCancel;
|
||||||
|
private Button buttonSave;
|
||||||
|
private Label label1;
|
||||||
|
private ComboBox comboBoxPosition;
|
||||||
|
private Label label3;
|
||||||
|
private DateTimePicker dateTimePicker1;
|
||||||
|
private TextBox textBoxAddress;
|
||||||
|
private Label label5;
|
||||||
|
private TextBox textBoxPhone;
|
||||||
|
private Label label6;
|
||||||
|
}
|
||||||
|
}
|
101
DepartmentStaffView/DepartmentStaffView/FormEmployee.cs
Normal file
101
DepartmentStaffView/DepartmentStaffView/FormEmployee.cs
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
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 : Form
|
||||||
|
{
|
||||||
|
private readonly Abstracts db;
|
||||||
|
public int? EmployeeId;
|
||||||
|
public FormEmployee(Abstracts abstracts)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
db = abstracts;
|
||||||
|
}
|
||||||
|
private void buttonSave_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//if (string.IsNullOrEmpty(textBox1.Text) || string.IsNullOrEmpty(textBox2.Text))
|
||||||
|
//{
|
||||||
|
// MessageBox.Show("Заполните поля. Они все обязательные!");
|
||||||
|
// return;
|
||||||
|
//}
|
||||||
|
if (EmployeeId.HasValue)
|
||||||
|
{
|
||||||
|
db.UpdateEmployee(new()
|
||||||
|
{
|
||||||
|
Id = EmployeeId.Value,
|
||||||
|
EmployeeName = textBoxName.Text,
|
||||||
|
Address = textBoxAddress.Text,
|
||||||
|
Email = textBoxEmail.Text,
|
||||||
|
PhoneNumber = textBoxPhone.Text,
|
||||||
|
Birthdate = dateTimePicker1.Value,
|
||||||
|
PositionId = (comboBoxPosition.SelectedItem as Position).Id,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
db.CreateEmployee(new()
|
||||||
|
{
|
||||||
|
EmployeeName = textBoxName.Text,
|
||||||
|
Address = textBoxAddress.Text,
|
||||||
|
Email = textBoxEmail.Text,
|
||||||
|
PhoneNumber = textBoxPhone.Text,
|
||||||
|
Birthdate = dateTimePicker1.Value,
|
||||||
|
PositionId = (comboBoxPosition.SelectedItem as Position).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 deps = db.GetPositions();
|
||||||
|
comboBoxPosition.DataSource = deps;
|
||||||
|
|
||||||
|
comboBoxPosition.DisplayMember = "PositionName";
|
||||||
|
comboBoxPosition.ValueMember = "Id";
|
||||||
|
|
||||||
|
if (EmployeeId.HasValue)
|
||||||
|
{
|
||||||
|
textBoxAddress.Text = db.GetEmployee(EmployeeId.Value).Address;
|
||||||
|
textBoxPhone.Text = db.GetEmployee(EmployeeId.Value).PhoneNumber;
|
||||||
|
textBoxEmail.Text = db.GetEmployee(EmployeeId.Value).Email;
|
||||||
|
textBoxName.Text = db.GetEmployee(EmployeeId.Value).EmployeeName;
|
||||||
|
dateTimePicker1.Value = db.GetEmployee(EmployeeId.Value).Birthdate;
|
||||||
|
comboBoxPosition.SelectedValue = db.GetEmployee(EmployeeId.Value).PositionId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void FormEmployee_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
60
DepartmentStaffView/DepartmentStaffView/FormEmployee.resx
Normal file
60
DepartmentStaffView/DepartmentStaffView/FormEmployee.resx
Normal 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>
|
102
DepartmentStaffView/DepartmentStaffView/FormEmployees.Designer.cs
generated
Normal file
102
DepartmentStaffView/DepartmentStaffView/FormEmployees.Designer.cs
generated
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
namespace DepartmentStaffView
|
||||||
|
{
|
||||||
|
partial class FormEmployees
|
||||||
|
{
|
||||||
|
/// <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();
|
||||||
|
((System.ComponentModel.ISupportInitialize)dataGridView1).BeginInit();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// buttonDelete
|
||||||
|
//
|
||||||
|
buttonDelete.Location = new Point(808, 117);
|
||||||
|
buttonDelete.Name = "buttonDelete";
|
||||||
|
buttonDelete.Size = new Size(75, 23);
|
||||||
|
buttonDelete.TabIndex = 12;
|
||||||
|
buttonDelete.Text = "Удалить";
|
||||||
|
buttonDelete.UseVisualStyleBackColor = true;
|
||||||
|
buttonDelete.Click += buttonDelete_Click;
|
||||||
|
//
|
||||||
|
// buttonгUpdate
|
||||||
|
//
|
||||||
|
buttonгUpdate.Location = new Point(808, 61);
|
||||||
|
buttonгUpdate.Name = "buttonгUpdate";
|
||||||
|
buttonгUpdate.Size = new Size(75, 23);
|
||||||
|
buttonгUpdate.TabIndex = 11;
|
||||||
|
buttonгUpdate.Text = "Обновить";
|
||||||
|
buttonгUpdate.UseVisualStyleBackColor = true;
|
||||||
|
buttonгUpdate.Click += buttonUpdate_Click;
|
||||||
|
//
|
||||||
|
// buttonCreate
|
||||||
|
//
|
||||||
|
buttonCreate.Location = new Point(808, 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(790, 320);
|
||||||
|
dataGridView1.TabIndex = 9;
|
||||||
|
//
|
||||||
|
// FormEmployees
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(926, 347);
|
||||||
|
Controls.Add(buttonDelete);
|
||||||
|
Controls.Add(buttonгUpdate);
|
||||||
|
Controls.Add(buttonCreate);
|
||||||
|
Controls.Add(dataGridView1);
|
||||||
|
Name = "FormEmployees";
|
||||||
|
Text = "FormEmployees";
|
||||||
|
Load += FormEmployees_Load;
|
||||||
|
((System.ComponentModel.ISupportInitialize)dataGridView1).EndInit();
|
||||||
|
ResumeLayout(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private Button buttonDelete;
|
||||||
|
private Button buttonгUpdate;
|
||||||
|
private Button buttonCreate;
|
||||||
|
private DataGridView dataGridView1;
|
||||||
|
}
|
||||||
|
}
|
83
DepartmentStaffView/DepartmentStaffView/FormEmployees.cs
Normal file
83
DepartmentStaffView/DepartmentStaffView/FormEmployees.cs
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
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 FormEmployees : Form
|
||||||
|
{
|
||||||
|
private readonly Abstracts db;
|
||||||
|
public FormEmployees(Abstracts abstracts)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
db = abstracts;
|
||||||
|
}
|
||||||
|
private void LoadData()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var list = db.GetEmployees();
|
||||||
|
dataGridView1.DataSource = list;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void FormEmployees_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
private void buttonCreate_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var service = Program.ServiceProvider?.GetService(typeof(FormEmployee));
|
||||||
|
if (service is FormEmployee 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(FormEmployee));
|
||||||
|
if (service is FormEmployee form)
|
||||||
|
{
|
||||||
|
form.EmployeeId = 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.DeleteEmployee(id);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
60
DepartmentStaffView/DepartmentStaffView/FormEmployees.resx
Normal file
60
DepartmentStaffView/DepartmentStaffView/FormEmployees.resx
Normal 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>
|
@ -30,6 +30,7 @@
|
|||||||
{
|
{
|
||||||
buttonDepartments = new Button();
|
buttonDepartments = new Button();
|
||||||
buttonPositions = new Button();
|
buttonPositions = new Button();
|
||||||
|
buttonEmployees = new Button();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
// buttonDepartments
|
// buttonDepartments
|
||||||
@ -52,11 +53,22 @@
|
|||||||
buttonPositions.UseVisualStyleBackColor = true;
|
buttonPositions.UseVisualStyleBackColor = true;
|
||||||
buttonPositions.Click += buttonPositions_Click;
|
buttonPositions.Click += buttonPositions_Click;
|
||||||
//
|
//
|
||||||
|
// buttonEmployees
|
||||||
|
//
|
||||||
|
buttonEmployees.Location = new Point(12, 131);
|
||||||
|
buttonEmployees.Name = "buttonEmployees";
|
||||||
|
buttonEmployees.Size = new Size(141, 44);
|
||||||
|
buttonEmployees.TabIndex = 2;
|
||||||
|
buttonEmployees.Text = "Работники";
|
||||||
|
buttonEmployees.UseVisualStyleBackColor = true;
|
||||||
|
buttonEmployees.Click += buttonEmployees_Click;
|
||||||
|
//
|
||||||
// FormMain
|
// FormMain
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(800, 450);
|
ClientSize = new Size(800, 450);
|
||||||
|
Controls.Add(buttonEmployees);
|
||||||
Controls.Add(buttonPositions);
|
Controls.Add(buttonPositions);
|
||||||
Controls.Add(buttonDepartments);
|
Controls.Add(buttonDepartments);
|
||||||
Name = "FormMain";
|
Name = "FormMain";
|
||||||
@ -68,5 +80,6 @@
|
|||||||
|
|
||||||
private Button buttonDepartments;
|
private Button buttonDepartments;
|
||||||
private Button buttonPositions;
|
private Button buttonPositions;
|
||||||
|
private Button buttonEmployees;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -35,5 +35,13 @@ namespace DepartmentStaffView
|
|||||||
form.Show();
|
form.Show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private void buttonEmployees_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var service = Program.ServiceProvider?.GetService(typeof(FormEmployees));
|
||||||
|
if (service is FormEmployees form)
|
||||||
|
{
|
||||||
|
form.Show();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -73,8 +73,9 @@ namespace DepartmentStaffView
|
|||||||
|
|
||||||
if (PositionId.HasValue)
|
if (PositionId.HasValue)
|
||||||
{
|
{
|
||||||
textBox1.Text = db.GetPosition(PositionId ?? default(int)).PositionName;
|
textBox1.Text = db.GetPosition(PositionId.Value).PositionName;
|
||||||
textBox2.Text = db.GetPosition(PositionId ?? default(int)).Salary.ToString();
|
textBox2.Text = db.GetPosition(PositionId.Value).Salary.ToString();
|
||||||
|
comboBoxDepartment.SelectedValue = db.GetPosition(PositionId.Value).DepartmentId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
@ -87,7 +87,7 @@
|
|||||||
Controls.Add(dataGridView1);
|
Controls.Add(dataGridView1);
|
||||||
Name = "FormPositions";
|
Name = "FormPositions";
|
||||||
Text = "FormPositions";
|
Text = "FormPositions";
|
||||||
Load += FormDepartments_Load;
|
Load += FormPositions_Load;
|
||||||
((System.ComponentModel.ISupportInitialize)dataGridView1).EndInit();
|
((System.ComponentModel.ISupportInitialize)dataGridView1).EndInit();
|
||||||
ResumeLayout(false);
|
ResumeLayout(false);
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ namespace DepartmentStaffView
|
|||||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void FormDepartments_Load(object sender, EventArgs e)
|
private void FormPositions_Load(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
LoadData();
|
LoadData();
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,8 @@ namespace DepartmentStaffView
|
|||||||
services.AddTransient<FormDepartment>();
|
services.AddTransient<FormDepartment>();
|
||||||
services.AddTransient<FormPositions>();
|
services.AddTransient<FormPositions>();
|
||||||
services.AddTransient<FormPosition>();
|
services.AddTransient<FormPosition>();
|
||||||
|
services.AddTransient<FormEmployees>();
|
||||||
|
services.AddTransient<FormEmployee>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user