diff --git a/.gitignore b/.gitignore
index 3c4efe2..8fc023c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -211,8 +211,6 @@ UpgradeLog*.XML
UpgradeLog*.htm
# SQL Server files
-*.mdf
-*.ldf
# Business Intelligence projects
*.rdl.data
diff --git a/BMO.GameDevUnity.CSharp2.Pract5/BMO.GameDevUnity.CSharp2.Pract5/MainWindow.xaml b/BMO.GameDevUnity.CSharp2.Pract5/BMO.GameDevUnity.CSharp2.Pract5/MainWindow.xaml
index da580ab..f098b1b 100644
--- a/BMO.GameDevUnity.CSharp2.Pract5/BMO.GameDevUnity.CSharp2.Pract5/MainWindow.xaml
+++ b/BMO.GameDevUnity.CSharp2.Pract5/BMO.GameDevUnity.CSharp2.Pract5/MainWindow.xaml
@@ -6,7 +6,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:BMO.GameDevUnity.CSharp2.Pract5"
mc:Ignorable="d"
- Title="Сотрудники организации" Height="450" Width="800">
+ Title="Сотрудники организации" Height="450" Width="800" Loaded="WndMain_Loaded">
@@ -33,17 +33,17 @@
-
+
-
-
-
-
+
+
+
+
-
+
diff --git a/BMO.GameDevUnity.CSharp2.Pract5/BMO.GameDevUnity.CSharp2.Pract5/MainWindow.xaml.cs b/BMO.GameDevUnity.CSharp2.Pract5/BMO.GameDevUnity.CSharp2.Pract5/MainWindow.xaml.cs
index 8a3a7dd..8edf46f 100644
--- a/BMO.GameDevUnity.CSharp2.Pract5/BMO.GameDevUnity.CSharp2.Pract5/MainWindow.xaml.cs
+++ b/BMO.GameDevUnity.CSharp2.Pract5/BMO.GameDevUnity.CSharp2.Pract5/MainWindow.xaml.cs
@@ -15,6 +15,8 @@
using System.IO;
using System.Xml.Serialization;
using Microsoft.Win32;
+using System.Data;
+using System.Data.SqlClient;
namespace BMO.GameDevUnity.CSharp2.Pract5
{
@@ -23,32 +25,21 @@ namespace BMO.GameDevUnity.CSharp2.Pract5
///
public partial class MainWindow : Window
{
- static public Organization MyOrganization { get; set; }
+ //static public Organization MyOrganization { get; set; }
static string fileName = "data.xml";
- public string TestStr { get; set; }
+
+ SqlConnection connection;
+ SqlDataAdapter adapterEmployees;
+ public static DataTable dtEmployees;
+ SqlDataAdapter adapterDepartments;
+ public static DataTable dtDepartments;
public MainWindow()
{
- MyOrganization = new Organization()
- {
- //{"Информационный", new Department() { Name = "Информационный" } },
- //{ "Административный", new Department() { Name = "Административный" } },
- //{ "Экономический", new Department() { Name = "Экономический" } }
- };
InitializeComponent();
- this.DataContext = this;
-
- if (cbDepartments.Items.Count == 0)
- {
- btnChangeDepartment.Visibility = Visibility.Hidden;
- btnDeleteDepartment.Visibility = Visibility.Hidden;
- }
- else
- {
- cbDepartments.Text = MyOrganization.Keys.First();
- }
+ this.DataContext = this;
btnDeleteEmployee.Visibility = Visibility.Hidden;
btnChangeEmployee.Visibility = Visibility.Hidden;
@@ -56,37 +47,109 @@ public MainWindow()
}
- private void BtnButton1_Click(object sender, RoutedEventArgs e)
+ private void WndMain_Loaded(object sender, RoutedEventArgs e)
{
- System.Windows.MessageBox.Show("Press");
- }
+ //string connectionString = @"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=MyDatabaseCSharpLev2Pract7;Integrated Security=True;Pooling=False";
+ // Из-за особенностей игнорирования Git, необходимо перенести базу данных из корня проекта в попку выполнения bin/Debug
+ string connectionString = @"Data Source=(localdb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\MyDatabaseCSharpLev2Pract7.mdf;Integrated Security=True;Pooling=False";
+ connection = new SqlConnection(connectionString);
+ adapterEmployees = new SqlDataAdapter();
+ adapterDepartments = new SqlDataAdapter();
+ // SELECT Departments
+ SqlCommand command = new SqlCommand("SELECT Id, name FROM Departments", connection);
+ adapterDepartments.SelectCommand = command;
+ // INSERT Department
+ command = new SqlCommand(@"INSERT INTO Departments(name) VALUES (@name); SET @Id = @@IDENTITY;", connection);
+ command.Parameters.Add("@name", SqlDbType.NVarChar, 50, "name");
+ SqlParameter param = command.Parameters.Add("@Id", SqlDbType.Int, 0, "Id");
+ param.Direction = ParameterDirection.Output;
+ adapterDepartments.InsertCommand = command;
- private void MiExit_Click(object sender, RoutedEventArgs e)
- {
- this.Close();
+ // UPDATE Department
+ command = new SqlCommand("UPDATE Departments SET name = @name WHERE Id = @Id", connection);
+ command.Parameters.Add("@name", SqlDbType.NVarChar, 50, "name");
+ param = command.Parameters.Add("@Id", SqlDbType.Int, 0, "Id");
+ param.SourceVersion = DataRowVersion.Original;
+ adapterDepartments.UpdateCommand = command;
+
+ // DELETE Department
+ command = new SqlCommand("DELETE FROM Departments WHERE Id = @Id", connection);
+ param = command.Parameters.Add("@Id", SqlDbType.Int, 0, "Id");
+ param.SourceVersion = DataRowVersion.Original;
+ adapterDepartments.DeleteCommand = command;
+
+ // Заполнение департаментов
+ dtDepartments = new DataTable();
+ adapterDepartments.Fill(dtDepartments);
+ dtDepartments.PrimaryKey = new DataColumn[1] { dtDepartments.Columns[0] };
+ dtDepartments.Columns[0].AutoIncrement = true;
+ dtDepartments.Columns[0].AutoIncrementStep = 1;
+ cbDepartments.DataContext = dtDepartments.DefaultView;
+ cbDepartments.Text = dtDepartments.Rows[0].ItemArray[1].ToString();
+ if (cbDepartments.Items.Count == 0)
+ {
+ btnChangeDepartment.Visibility = Visibility.Hidden;
+ btnDeleteDepartment.Visibility = Visibility.Hidden;
+ }
+
+
+ // SELECT Employees
+ command = new SqlCommand($"SELECT Id, last_name, first_name, profession, age, id_department FROM Employees WHERE id_department = {dtDepartments.Rows[0].ItemArray[0]}", connection);
+ adapterEmployees.SelectCommand = command;
+
+ // INSERT Employee
+ command = new SqlCommand(@"INSERT INTO Employees(last_name, first_name, profession, age, id_department) VALUES (@last_name, @first_name, @profession, @age, @id_department); SET @Id = @@IDENTITY;", connection);
+ command.Parameters.Add("@last_name", SqlDbType.NVarChar, 50, "last_name");
+ command.Parameters.Add("@first_name", SqlDbType.NVarChar, 50, "first_name");
+ command.Parameters.Add("@profession", SqlDbType.NVarChar, 50, "profession");
+ command.Parameters.Add("@age", SqlDbType.Int, 0, "age");
+ command.Parameters.Add("@id_department", SqlDbType.Int, 0, "id_department");
+ param = command.Parameters.Add("@Id", SqlDbType.Int, 0, "Id");
+ param.Direction = ParameterDirection.Output;
+ adapterEmployees.InsertCommand = command;
+
+ // UPDATE Employee
+ command = new SqlCommand("UPDATE Employees SET last_name = @last_name, first_name = @first_name, profession = @profession, age = @age, id_department = @id_department WHERE Id = @Id", connection);
+ command.Parameters.Add("@last_name", SqlDbType.NVarChar, 50, "last_name");
+ command.Parameters.Add("@first_name", SqlDbType.NVarChar, 50, "first_name");
+ command.Parameters.Add("@profession", SqlDbType.NVarChar, 50, "profession");
+ command.Parameters.Add("@age", SqlDbType.Int, 0, "age");
+ command.Parameters.Add("@id_department", SqlDbType.Int, 0, "id_department");
+ param = command.Parameters.Add("@Id", SqlDbType.Int, 0, "Id");
+ param.SourceVersion = DataRowVersion.Original;
+ adapterEmployees.UpdateCommand = command;
+
+ // DELETE Emmployee
+ command = new SqlCommand("DELETE FROM Employees WHERE Id = @Id", connection);
+ param = command.Parameters.Add("@Id", SqlDbType.Int, 0, "Id");
+ param.SourceVersion = DataRowVersion.Original;
+ adapterEmployees.DeleteCommand = command;
+
+ // Заполнение сотрудников
+ dtEmployees = new DataTable();
+ adapterEmployees.Fill(dtEmployees);
+ dtEmployees.PrimaryKey = new DataColumn[1] { dtEmployees.Columns[0] };
+ lvEmployees.DataContext = dtEmployees.DefaultView;
}
- private void BtnAddEmployee_Click(object sender, RoutedEventArgs e)
+ private void MiExit_Click(object sender, RoutedEventArgs e)
{
- wndNewEmployee wndNewEmployee = new wndNewEmployee();
- if (wndNewEmployee.ShowDialog() == true)
- {
- MyOrganization[wndNewEmployee.NameOfDepartment].Add(wndNewEmployee.ForExchange);
- cbDepartments.Text = wndNewEmployee.NameOfDepartment;
- UpdateListBoxEmployee(wndNewEmployee.NameOfDepartment);
- };
+ this.Close();
}
void UpdateCheckBoxDepartments()
{
- cbDepartments.Items.Refresh();
if (cbDepartments.Items.Count != 0)
{
- cbDepartments.SelectedItem = cbDepartments.Items[cbDepartments.Items.Count - 1];
- cbDepartments.Text = (cbDepartments.Items.Count == 1)?(cbDepartments.Text = cbDepartments.Items[cbDepartments.Items.IndexOf(cbDepartments.SelectedItem)].ToString()):(cbDepartments.Items[0].ToString());
- UpdateListBoxEmployee(cbDepartments.Text);
+ if (cbDepartments.SelectedItem == null)
+ {
+ cbDepartments.SelectedItem = cbDepartments.Items[cbDepartments.Items.Count - 1];
+ }
+ DataRowView department = (DataRowView)cbDepartments.SelectedItem;
+ cbDepartments.Text = department.Row.ItemArray[1].ToString();
+ UpdateListBoxEmployee();
btnDeleteDepartment.Visibility = Visibility.Visible;
btnChangeDepartment.Visibility = Visibility.Visible;
}
@@ -98,10 +161,14 @@ void UpdateCheckBoxDepartments()
}
}
- void UpdateListBoxEmployee(string NameOfDepartment)
+ void UpdateListBoxEmployee()
{
- lvEmployees.ItemsSource = MyOrganization[cbDepartments.Text];
- lvEmployees.Items.Refresh();
+ DataRowView department = (DataRowView)cbDepartments.SelectedItem;
+ SqlCommand command = new SqlCommand($"SELECT Id, last_name, first_name, profession, age, id_department FROM Employees WHERE id_department = {department.Row.ItemArray[0]}", connection);
+ adapterEmployees.SelectCommand = command;
+ dtEmployees.Clear();
+ adapterEmployees.Fill(dtEmployees);
+
if (cbDepartments.Items.Count != 0)
{
btnDeleteDepartment.Visibility = Visibility.Visible;
@@ -121,7 +188,7 @@ private void MiSave_Click(object sender, RoutedEventArgs e)
{
XmlSerializer xmlSerializer = new XmlSerializer(typeof(Organization));
FileStream fileStream = new FileStream(fileName, FileMode.Create, FileAccess.Write);
- xmlSerializer.Serialize(fileStream, MyOrganization);
+ //xmlSerializer.Serialize(fileStream, MyOrganization);
fileStream.Close();
}
@@ -130,7 +197,7 @@ private void CbDepartments_DropDownClosed(object sender, EventArgs e)
{
if (cbDepartments.Items.Count != 0)
{
- UpdateListBoxEmployee(cbDepartments.Text);
+ UpdateListBoxEmployee();
}
else
{
@@ -147,11 +214,11 @@ private void MiLoad_Click(object sender, RoutedEventArgs e)
fileName = ofd.FileName;
XmlSerializer xmlFormat = new XmlSerializer(typeof(Organization));
Stream fStream = new FileStream(ofd.FileName, FileMode.Open, FileAccess.Read);
- MyOrganization = (Organization)xmlFormat.Deserialize(fStream);
+ //MyOrganization = (Organization)xmlFormat.Deserialize(fStream);
UpdateCheckBoxDepartments();
if (cbDepartments.Items.Count != 0)
{
- UpdateListBoxEmployee(cbDepartments.Text);
+ UpdateListBoxEmployee();
}
fStream.Close();
}
@@ -167,29 +234,47 @@ private void MiSaveAs_Click(object sender, RoutedEventArgs e)
fileName = sfd.FileName;
XmlSerializer xmlSerializer = new XmlSerializer(typeof(Organization));
FileStream fileStream = new FileStream(sfd.FileName, FileMode.Create, FileAccess.Write);
- xmlSerializer.Serialize(fileStream, MyOrganization);
+ //xmlSerializer.Serialize(fileStream, MyOrganization);
fileStream.Close();
}
}
+ private void BtnAddEmployee_Click(object sender, RoutedEventArgs e)
+ {
+ DataRow newRow = dtEmployees.NewRow();
+ wndNewEmployee wndNewEmployee = new wndNewEmployee(newRow);
+ if (wndNewEmployee.ShowDialog() == true)
+ {
+ dtEmployees.Rows.Add(wndNewEmployee.resultRow);
+ adapterEmployees.Update(dtEmployees);
+ cbDepartments.Text = dtDepartments.Rows.Find((int)wndNewEmployee.resultRow["id_department"]).ItemArray[1].ToString();
+ UpdateListBoxEmployee();
+ };
+ }
+
private void BtnAddDepartment_Click(object sender, RoutedEventArgs e)
{
- wndNewDepartment wndNewDepartment = new wndNewDepartment();
+ DataRow newRow = dtDepartments.NewRow();
+ wndNewDepartment wndNewDepartment = new wndNewDepartment(newRow);
if (wndNewDepartment.ShowDialog() == true)
{
- MyOrganization.Add(wndNewDepartment.NameOfDepartment, new Department() { Name = wndNewDepartment.NameOfDepartment });
+ dtDepartments.Rows.Add(wndNewDepartment.resultRow);
+ adapterDepartments.Update(dtDepartments);
+ cbDepartments.SelectedItem = dtDepartments.Rows.Find((int)wndNewDepartment.resultRow["Id"]);
UpdateCheckBoxDepartments();
- cbDepartments.Text = wndNewDepartment.NameOfDepartment;
- UpdateListBoxEmployee(wndNewDepartment.NameOfDepartment);
+ cbDepartments.Text = dtDepartments.Rows.Find((int)wndNewDepartment.resultRow["Id"]).ItemArray[1].ToString();
+ UpdateListBoxEmployee();
};
}
private void BtnDeleteEmployee_Click(object sender, RoutedEventArgs e)
{
+ DataRowView newRow = (DataRowView)lvEmployees.SelectedItem;
if (lvEmployees.SelectedItem != null)
{
- MyOrganization[cbDepartments.Text].Remove((Employee)lvEmployees.SelectedItem);
- UpdateListBoxEmployee(cbDepartments.Text);
+ newRow.Row.Delete();
+ adapterEmployees.Update(dtEmployees);
+ UpdateListBoxEmployee();
}
else
{
@@ -199,9 +284,11 @@ private void BtnDeleteEmployee_Click(object sender, RoutedEventArgs e)
private void BtnDeleteDepartment_Click(object sender, RoutedEventArgs e)
{
+ DataRowView newRow = (DataRowView)cbDepartments.SelectedItem;
if (cbDepartments.Items.Count != 0)
{
- MyOrganization.Remove(cbDepartments.Text);
+ newRow.Row.Delete();
+ adapterDepartments.Update(dtDepartments);
UpdateCheckBoxDepartments();
}
else
@@ -212,22 +299,22 @@ private void BtnDeleteDepartment_Click(object sender, RoutedEventArgs e)
private void BtnChangeEmployee_Click(object sender, RoutedEventArgs e)
{
- wndChangeEmployee wndChangeEmployee = new wndChangeEmployee();
+ DataRowView newRow = (DataRowView)lvEmployees.SelectedItem;
+ newRow.BeginEdit();
+ wndChangeEmployee wndChangeEmployee = new wndChangeEmployee(newRow.Row);
if (lvEmployees.SelectedItem != null)
{
- Employee employeeBuffer = (Employee)lvEmployees.SelectedItem;
- wndChangeEmployee.LastName = employeeBuffer.LastName;
- wndChangeEmployee.FirstName = employeeBuffer.FirstName;
- wndChangeEmployee.Profession = employeeBuffer.Profession;
- wndChangeEmployee.Age = employeeBuffer.Age;
- wndChangeEmployee.Department = cbDepartments.Text;
if (wndChangeEmployee.ShowDialog() == true)
{
- MyOrganization[cbDepartments.Text].Remove((Employee)lvEmployees.SelectedItem);
- MyOrganization[wndChangeEmployee.Department].Add(wndChangeEmployee.ForExchange);
- cbDepartments.Text = wndChangeEmployee.Department;
- UpdateListBoxEmployee(wndChangeEmployee.Department);
- };
+ newRow.EndEdit();
+ adapterEmployees.Update(dtEmployees);
+ cbDepartments.Text = dtDepartments.Rows.Find((int)wndChangeEmployee.resultRow["id_department"]).ItemArray[1].ToString();
+ UpdateListBoxEmployee();
+ }
+ else
+ {
+ newRow.CancelEdit();
+ }
}
else
{
@@ -237,20 +324,24 @@ private void BtnChangeEmployee_Click(object sender, RoutedEventArgs e)
private void BtnChangeDepartment_Click(object sender, RoutedEventArgs e)
{
- wndChangeDepartment wndChangeDepartment = new wndChangeDepartment();
+ DataRowView newRow = (DataRowView)cbDepartments.SelectedItem;
+ newRow.BeginEdit();
+ wndChangeDepartment wndChangeDepartment = new wndChangeDepartment(newRow.Row);
if (cbDepartments.Items.Count != 0)
- {
- Department employeesBuffer = MyOrganization[cbDepartments.Text];
- wndChangeDepartment.Department = cbDepartments.Text;
+ {
if (wndChangeDepartment.ShowDialog() == true)
{
- MyOrganization.Remove(cbDepartments.Text);
- employeesBuffer.Name = wndChangeDepartment.Department;
- MyOrganization.Add(wndChangeDepartment.Department, employeesBuffer);
+ newRow.EndEdit();
+ adapterDepartments.Update(dtDepartments);
+ cbDepartments.SelectedItem = dtDepartments.Rows.Find((int)wndChangeDepartment.resultRow["Id"]);
+ cbDepartments.Text = dtDepartments.Rows.Find((int)wndChangeDepartment.resultRow["Id"]).ItemArray[1].ToString();
UpdateCheckBoxDepartments();
- cbDepartments.Text = wndChangeDepartment.Department;
- UpdateListBoxEmployee(wndChangeDepartment.Department);
- };
+ UpdateListBoxEmployee();
+ }
+ else
+ {
+ newRow.CancelEdit();
+ }
}
else
{
diff --git a/BMO.GameDevUnity.CSharp2.Pract5/BMO.GameDevUnity.CSharp2.Pract5/wndChangeDepartment.xaml.cs b/BMO.GameDevUnity.CSharp2.Pract5/BMO.GameDevUnity.CSharp2.Pract5/wndChangeDepartment.xaml.cs
index 15bc5b3..780ecec 100644
--- a/BMO.GameDevUnity.CSharp2.Pract5/BMO.GameDevUnity.CSharp2.Pract5/wndChangeDepartment.xaml.cs
+++ b/BMO.GameDevUnity.CSharp2.Pract5/BMO.GameDevUnity.CSharp2.Pract5/wndChangeDepartment.xaml.cs
@@ -11,6 +11,7 @@
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
+using System.Data;
namespace BMO.GameDevUnity.CSharp2.Pract5
{
@@ -19,17 +20,20 @@ namespace BMO.GameDevUnity.CSharp2.Pract5
///
public partial class wndChangeDepartment : Window
{
- public string Department { get; set; }
- public wndChangeDepartment()
+ public DataRow resultRow { get; set; }
+
+ public wndChangeDepartment(DataRow newRow)
{
InitializeComponent();
this.DataContext = this;
+
+ resultRow = newRow;
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
- tbNameDepartment.Text = Department;
+ tbNameDepartment.Text = resultRow["name"].ToString();
}
private void BtnOK_Click(object sender, RoutedEventArgs e)
@@ -40,7 +44,7 @@ private void BtnOK_Click(object sender, RoutedEventArgs e)
}
else
{
- Department = tbNameDepartment.Text;
+ resultRow["name"] = tbNameDepartment.Text;
this.DialogResult = true;
}
@@ -55,7 +59,7 @@ private void BtnCancel_Click(object sender, RoutedEventArgs e)
private void BtnReset_Click(object sender, RoutedEventArgs e)
{
- tbNameDepartment.Text = Department;
+ tbNameDepartment.Text = resultRow["name"].ToString();
}
}
}
diff --git a/BMO.GameDevUnity.CSharp2.Pract5/BMO.GameDevUnity.CSharp2.Pract5/wndChangeEmployee.xaml b/BMO.GameDevUnity.CSharp2.Pract5/BMO.GameDevUnity.CSharp2.Pract5/wndChangeEmployee.xaml
index 1b1a7eb..1bee24e 100644
--- a/BMO.GameDevUnity.CSharp2.Pract5/BMO.GameDevUnity.CSharp2.Pract5/wndChangeEmployee.xaml
+++ b/BMO.GameDevUnity.CSharp2.Pract5/BMO.GameDevUnity.CSharp2.Pract5/wndChangeEmployee.xaml
@@ -16,7 +16,7 @@
-
+
diff --git a/BMO.GameDevUnity.CSharp2.Pract5/BMO.GameDevUnity.CSharp2.Pract5/wndChangeEmployee.xaml.cs b/BMO.GameDevUnity.CSharp2.Pract5/BMO.GameDevUnity.CSharp2.Pract5/wndChangeEmployee.xaml.cs
index 2f7cc91..a7ccaed 100644
--- a/BMO.GameDevUnity.CSharp2.Pract5/BMO.GameDevUnity.CSharp2.Pract5/wndChangeEmployee.xaml.cs
+++ b/BMO.GameDevUnity.CSharp2.Pract5/BMO.GameDevUnity.CSharp2.Pract5/wndChangeEmployee.xaml.cs
@@ -11,6 +11,7 @@
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
+using System.Data;
namespace BMO.GameDevUnity.CSharp2.Pract5
{
@@ -19,23 +20,15 @@ namespace BMO.GameDevUnity.CSharp2.Pract5
///
public partial class wndChangeEmployee : Window
{
- public string LastName { get; set; }
- public string FirstName { get; set; }
- public string Profession { get; set; }
- public int Age { get; set; }
- public string Department { get; set; }
- public Employee ForExchange { get; set; }
+ public DataRow resultRow { get; set; }
- public wndChangeEmployee()
+ public wndChangeEmployee(DataRow newRow)
{
InitializeComponent();
this.DataContext = this;
- foreach (var department in MainWindow.MyOrganization)
- {
- cbDepartments.Items.Add(department.Key);
- }
+ resultRow = newRow;
}
private void BtnCancel_Click(object sender, RoutedEventArgs e)
@@ -48,34 +41,39 @@ private void BtnOK_Click(object sender, RoutedEventArgs e)
{
try
{
- ForExchange = new Employee(tbLastName.Text, tbFirstName.Text, tbProfession.Text, Convert.ToInt32(tbAge.Text));
- Department = cbDepartments.Text;
+ resultRow["first_name"] = tbFirstName.Text;
+ resultRow["last_name"] = tbLastName.Text;
+ resultRow["profession"] = tbProfession.Text;
+ resultRow["age"] = tbAge.Text;
+ DataRowView department = (DataRowView)cbDepartments.SelectedItem;
+ resultRow["id_department"] = department.Row.ItemArray[0];
this.DialogResult = true;
}
catch (Exception)
{
MessageBox.Show("Введены некорректные данные", "Ошибка!", MessageBoxButton.OK, MessageBoxImage.Error);
- }
+ }
this.Close();
}
private void BtnReset_Click(object sender, RoutedEventArgs e)
{
- tbLastName.Text = LastName;
- tbFirstName.Text = FirstName;
- tbProfession.Text = Profession;
- tbAge.Text = Age.ToString();
- cbDepartments.Text = Department;
+ tbFirstName.Text = resultRow["first_name"].ToString();
+ tbLastName.Text = resultRow["last_name"].ToString();
+ tbProfession.Text = resultRow["profession"].ToString();
+ tbAge.Text = resultRow["age"].ToString();
+ cbDepartments.Text = MainWindow.dtDepartments.Rows.Find((int)resultRow["id_department"]).ItemArray[1].ToString();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
- tbLastName.Text = LastName;
- tbFirstName.Text = FirstName;
- tbProfession.Text = Profession;
- tbAge.Text = Age.ToString();
- cbDepartments.Text = Department;
+ tbFirstName.Text = resultRow["first_name"].ToString();
+ tbLastName.Text = resultRow["last_name"].ToString();
+ tbProfession.Text = resultRow["profession"].ToString();
+ tbAge.Text = resultRow["age"].ToString();
+ cbDepartments.DataContext = MainWindow.dtDepartments.DefaultView;
+ cbDepartments.Text = MainWindow.dtDepartments.Rows.Find((int)resultRow["id_department"]).ItemArray[1].ToString();
}
}
}
diff --git a/BMO.GameDevUnity.CSharp2.Pract5/BMO.GameDevUnity.CSharp2.Pract5/wndNewDepartment.xaml b/BMO.GameDevUnity.CSharp2.Pract5/BMO.GameDevUnity.CSharp2.Pract5/wndNewDepartment.xaml
index a128dfc..281889b 100644
--- a/BMO.GameDevUnity.CSharp2.Pract5/BMO.GameDevUnity.CSharp2.Pract5/wndNewDepartment.xaml
+++ b/BMO.GameDevUnity.CSharp2.Pract5/BMO.GameDevUnity.CSharp2.Pract5/wndNewDepartment.xaml
@@ -5,7 +5,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:BMO.GameDevUnity.CSharp2.Pract5"
mc:Ignorable="d"
- Title="Добавление нового департамента" Height="120" Width="310">
+ Title="Добавление нового департамента" Height="120" Width="310" Loaded="Window_Loaded">
diff --git a/BMO.GameDevUnity.CSharp2.Pract5/BMO.GameDevUnity.CSharp2.Pract5/wndNewDepartment.xaml.cs b/BMO.GameDevUnity.CSharp2.Pract5/BMO.GameDevUnity.CSharp2.Pract5/wndNewDepartment.xaml.cs
index 1226628..f8bea2e 100644
--- a/BMO.GameDevUnity.CSharp2.Pract5/BMO.GameDevUnity.CSharp2.Pract5/wndNewDepartment.xaml.cs
+++ b/BMO.GameDevUnity.CSharp2.Pract5/BMO.GameDevUnity.CSharp2.Pract5/wndNewDepartment.xaml.cs
@@ -11,6 +11,7 @@
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
+using System.Data;
namespace BMO.GameDevUnity.CSharp2.Pract5
{
@@ -19,13 +20,13 @@ namespace BMO.GameDevUnity.CSharp2.Pract5
///
public partial class wndNewDepartment : Window
{
- public string NameOfDepartment { get; set; }
+ public DataRow resultRow { get; set; }
- public wndNewDepartment()
+ public wndNewDepartment(DataRow newRow)
{
InitializeComponent();
- this.DataContext = this;
+ resultRow = newRow;
}
private void BtnOK_Click(object sender, RoutedEventArgs e)
@@ -36,11 +37,16 @@ private void BtnOK_Click(object sender, RoutedEventArgs e)
}
else
{
- NameOfDepartment = tbNameDepartment.Text;
+ resultRow["name"] = tbNameDepartment.Text;
this.DialogResult = true;
}
this.Close();
}
+
+ private void Window_Loaded(object sender, RoutedEventArgs e)
+ {
+ tbNameDepartment.Text = resultRow["name"].ToString();
+ }
}
}
diff --git a/BMO.GameDevUnity.CSharp2.Pract5/BMO.GameDevUnity.CSharp2.Pract5/wndNewEmployee.xaml b/BMO.GameDevUnity.CSharp2.Pract5/BMO.GameDevUnity.CSharp2.Pract5/wndNewEmployee.xaml
index 7eca65a..9ca09d7 100644
--- a/BMO.GameDevUnity.CSharp2.Pract5/BMO.GameDevUnity.CSharp2.Pract5/wndNewEmployee.xaml
+++ b/BMO.GameDevUnity.CSharp2.Pract5/BMO.GameDevUnity.CSharp2.Pract5/wndNewEmployee.xaml
@@ -5,7 +5,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:BMO.GameDevUnity.CSharp2.Pract5"
mc:Ignorable="d"
- Title="Добавление нового сотрудника" Height="300" Width="350">
+ Title="Добавление нового сотрудника" Height="300" Width="350" Loaded="Window_Loaded">
@@ -16,7 +16,7 @@
-
+
\ No newline at end of file
diff --git a/BMO.GameDevUnity.CSharp2.Pract5/BMO.GameDevUnity.CSharp2.Pract5/wndNewEmployee.xaml.cs b/BMO.GameDevUnity.CSharp2.Pract5/BMO.GameDevUnity.CSharp2.Pract5/wndNewEmployee.xaml.cs
index c0b3a85..a28be5d 100644
--- a/BMO.GameDevUnity.CSharp2.Pract5/BMO.GameDevUnity.CSharp2.Pract5/wndNewEmployee.xaml.cs
+++ b/BMO.GameDevUnity.CSharp2.Pract5/BMO.GameDevUnity.CSharp2.Pract5/wndNewEmployee.xaml.cs
@@ -11,6 +11,8 @@
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
+using System.Data;
+using System.Data.SqlClient;
namespace BMO.GameDevUnity.CSharp2.Pract5
{
@@ -19,28 +21,27 @@ namespace BMO.GameDevUnity.CSharp2.Pract5
///
public partial class wndNewEmployee : Window
{
- public Employee ForExchange { get; set; }
- public string NameOfDepartment { get; set; }
+ public DataRow resultRow { get; set; }
- public wndNewEmployee()
+ public wndNewEmployee(DataRow newRow)
{
InitializeComponent();
this.DataContext = this;
- foreach (var department in MainWindow.MyOrganization)
- {
- cbDepartments.Items.Add(department.Key);
- }
- cbDepartments.Text = cbDepartments.Items[0].ToString();
+ resultRow = newRow;
}
private void BtnOK_Click(object sender, RoutedEventArgs e)
{
try
{
- ForExchange = new Employee(tbLastName.Text, tbFirstName.Text, tbProfession.Text, Convert.ToInt32(tbAge.Text));
- NameOfDepartment = cbDepartments.Text;
+ resultRow["first_name"] = tbFirstName.Text;
+ resultRow["last_name"] = tbLastName.Text;
+ resultRow["profession"] = tbProfession.Text;
+ resultRow["age"] = tbAge.Text;
+ DataRowView department = (DataRowView)cbDepartments.SelectedItem;
+ resultRow["id_department"] = department.Row.ItemArray[0];
this.DialogResult = true;
}
catch (Exception)
@@ -50,5 +51,15 @@ private void BtnOK_Click(object sender, RoutedEventArgs e)
}
this.Close();
}
+
+ private void Window_Loaded(object sender, RoutedEventArgs e)
+ {
+ tbFirstName.Text = resultRow["first_name"].ToString();
+ tbLastName.Text = resultRow["last_name"].ToString();
+ tbProfession.Text = resultRow["profession"].ToString();
+ tbAge.Text = resultRow["age"].ToString();
+ cbDepartments.DataContext = MainWindow.dtDepartments.DefaultView;
+ cbDepartments.Text = MainWindow.dtDepartments.Rows[0].ItemArray[1].ToString();
+ }
}
}
diff --git a/BMO.GameDevUnity.CSharp2.Pract5/MyDatabaseCSharpLev2Pract7.ldf b/BMO.GameDevUnity.CSharp2.Pract5/MyDatabaseCSharpLev2Pract7.ldf
new file mode 100644
index 0000000..d207e17
Binary files /dev/null and b/BMO.GameDevUnity.CSharp2.Pract5/MyDatabaseCSharpLev2Pract7.ldf differ
diff --git a/BMO.GameDevUnity.CSharp2.Pract5/MyDatabaseCSharpLev2Pract7.mdf b/BMO.GameDevUnity.CSharp2.Pract5/MyDatabaseCSharpLev2Pract7.mdf
new file mode 100644
index 0000000..34793ce
Binary files /dev/null and b/BMO.GameDevUnity.CSharp2.Pract5/MyDatabaseCSharpLev2Pract7.mdf differ