1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- 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 System.Data.SqlClient;
- namespace proba
- {
- public partial class PersonalArea : Form
- {
- DataBase dataBase = new DataBase();
- public PersonalArea()
- {
- InitializeComponent();
- // TODO: данная строка кода позволяет загрузить данные в таблицу "vINILDataSet_Pol.Pol". При необходимости она может быть перемещена или удалена.
- this.polTableAdapter.Fill(this.vINILDataSet_Pol.Pol);
- dataBase.openConnection();
- SqlCommand sqlCommand_surname = new SqlCommand($"SELECT surname From Employee WHERE login = '{PosleVHODA.login}'", dataBase.GetConnection());
- surname.Text = sqlCommand_surname.ExecuteScalar().ToString();
- SqlCommand sqlCommand_name = new SqlCommand($"SELECT name From Employee WHERE login = '{PosleVHODA.login}'", dataBase.GetConnection());
- name.Text = sqlCommand_name.ExecuteScalar().ToString();
- SqlCommand sqlCommand_patronymic = new SqlCommand($"SELECT patronymic From Employee WHERE login = '{PosleVHODA.login}'", dataBase.GetConnection());
- patronymic.Text = sqlCommand_patronymic.ExecuteScalar().ToString();
- SqlCommand sqlCommand_pol = new SqlCommand($"SELECT P.pol From Employee E inner join Pol P ON E.id_pol=P.id_pol WHERE E.login = '{PosleVHODA.login}'", dataBase.GetConnection());
- text_id_pol.Text = sqlCommand_pol.ExecuteScalar().ToString();
- SqlCommand sqlCommand_date_of_birth = new SqlCommand($"SELECT date_of_birth From Employee WHERE login = '{PosleVHODA.login}'", dataBase.GetConnection());
- date_of_birth.Text = sqlCommand_date_of_birth.ExecuteScalar().ToString();
- SqlCommand sqlCommand_phone = new SqlCommand($"SELECT phone From Employee WHERE login = '{PosleVHODA.login}'", dataBase.GetConnection());
- phone.Text = sqlCommand_phone.ExecuteScalar().ToString();
- text_login.Text = PosleVHODA.login;
- }
- private void button_back_Click(object sender, EventArgs e)
- {
- this.Hide();
- MainMenu mainMenu = new MainMenu();
- mainMenu.ShowDialog();
- }
- public void global_FormClosed(object sender, EventArgs e)
- {
- Application.Exit();
- }
- private void button_save_Click(object sender, EventArgs e)
- {
- string sqccommand_pol = $"SELECT id_pol From Pol WHERE pol = '{text_id_pol.Text}'";
- SqlDataAdapter sda = new SqlDataAdapter(sqccommand_pol, dataBase.GetConnection());
- DataTable dtbl = new DataTable();
- sda.Fill(dtbl);
- if (dtbl.Rows.Count == 0)
- {
- MessageBox.Show("Поле пол должно быть выбрано из списка");
- }
- else if (text_login.TextLength > 15) MessageBox.Show("Максимальная длина логина – 15 символов");
- else if (text_login.Text.Replace(" ", "") == "") MessageBox.Show("Поле логина не может быть пустым");
- else if (surname.Text.Replace(" ", "") == "") MessageBox.Show("Поле фамилия не может быть пустым");
- else if (name.Text.Replace(" ", "") == "") MessageBox.Show("Поле имя не может быть пустым");
- else if (patronymic.Text.Replace(" ", "") == "") MessageBox.Show("Поле отчество не может быть пустым");
- else if (date_of_birth.Text.Replace(" ", "") == "") MessageBox.Show("Поле дата рождения не может быть пустым");
- else
- {
- var confirmResult = MessageBox.Show("Вы точно хотите изменить личные данные?", "Подтвердите изменение!", MessageBoxButtons.YesNo);
- if (confirmResult == DialogResult.Yes)
- {
- dataBase.openConnection();
- string id_pol;
- SqlCommand sqlCommand_pol = new SqlCommand(sqccommand_pol, dataBase.GetConnection());
- id_pol = sqlCommand_pol.ExecuteScalar().ToString();
- var addQuery = $"update Employee set surname = '{surname.Text}', name = '{name.Text}', patronymic = '{patronymic.Text}', id_pol = '{id_pol}', date_of_birth = '{date_of_birth.Text}', phone = '{phone.Text}', login = '{text_login.Text}' where login = '{PosleVHODA.login}'";
- var command = new SqlCommand(addQuery, dataBase.GetConnection());
- command.ExecuteNonQuery();
- MessageBox.Show("Личные данные изменены");
- PosleVHODA.login = text_login.Text;
- dataBase.closeConnection();
- }
- }
- }
- private void button_change_password_Click(object sender, EventArgs e)
- {
- this.Hide();
- PasswordChange passwordChange = new PasswordChange();
- passwordChange.ShowDialog();
- }
- private void phone_KeyPress(object sender, KeyPressEventArgs e)
- {
- char number = e.KeyChar;
- if (!Char.IsDigit(number) && number != 8 && !(e.KeyChar == '+') && !(e.KeyChar == '(') && !(e.KeyChar == ')'))
- {
- e.Handled = true;
- }
- }
- }
- }
|