using Servise.Classes;
using Servise.Forms.User;
using System;
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;
namespace Servise.Forms
{
public partial class Users : Form
{
DataBase conect = new DataBase();
public Users()
{
InitializeComponent();
}
private void Users_Load(object sender, EventArgs e)
{
textName.ReadOnly = true;
textSurname.ReadOnly = true;
textEmail.ReadOnly = true;
maskedPhone.ReadOnly = true;
textLogin.ReadOnly = true;
textPatronymic.ReadOnly = true;
conect.openConect();
SqlCommand sql = new SqlCommand("Select name From employees where login='" + UserInform.Login + "'", conect.getConect());
textName.Text = sql.ExecuteScalar().ToString();
sql = new SqlCommand("Select surname From employees where login='" + UserInform.Login + "'", conect.getConect());
textSurname.Text = sql.ExecuteScalar().ToString();
sql = new SqlCommand("Select patronymic From employees where login='" + UserInform.Login + "'", conect.getConect());
textPatronymic.Text = sql.ExecuteScalar().ToString();
sql = new SqlCommand("Select email From employees where login='" + UserInform.Login + "'", conect.getConect());
textEmail.Text = sql.ExecuteScalar().ToString();
sql = new SqlCommand("Select phone From employees where login='" + UserInform.Login + "'", conect.getConect());
maskedPhone.Text = sql.ExecuteScalar().ToString();
sql = new SqlCommand("Select login From employees where login='" + UserInform.Login + "'", conect.getConect());
textLogin.Text = sql.ExecuteScalar().ToString();
}
private void button4_Click(object sender, EventArgs e)
{
textName.ReadOnly = false;
textSurname.ReadOnly = false;
textEmail.ReadOnly = false;
maskedPhone.ReadOnly = false;
textLogin.ReadOnly = false;
textPatronymic.ReadOnly = false;
}
private void button3_Click(object sender, EventArgs e)
{
conect.openConect(); ;
string n = textName.Text;
string s = textSurname.Text;
string p = textPatronymic.Text;
string ph = maskedPhone.Text;
string em = textEmail.Text;
string l = textLogin.Text.Trim();
string query = "Select *from employees where login = '" + l + "'";
SqlDataAdapter sda = new SqlDataAdapter(query, conect.getConect());
DataTable dtbl = new DataTable();
sda.Fill(dtbl);
if (dtbl.Rows.Count == 0)
{
var indert = "update employees set name = '" + n + "'," + "surname= '" + s + "'," + "patronymic= '" + p + "'," + "phone= '" + ph + "'," + "email= '" + em + "'," + "login= '" + l + "' where login ='" + UserInform.Login + "'";
var command = new SqlCommand(indert, conect.getConect());
command.ExecuteNonQuery();
UserInform.Login = textLogin.Text.Trim();
textName.ReadOnly = true;
textSurname.ReadOnly = true;
textEmail.ReadOnly = true;
maskedPhone.ReadOnly = true;
textLogin.ReadOnly = true;
textPatronymic.ReadOnly = true;
}
else
{
MessageBox.Show("Логин занят");
}
conect.closeConect();
conect.closeConect();
}
private void Users_FormClosing(object sender, FormClosedEventArgs e)
{
Application.Exit();
}
///
/// Кнопки для переходов на соответствующие страницы
///
///
///
private void button2_Click(object sender, EventArgs e)
{
this.Hide();
AddZac goUser = new AddZac();
goUser.Show();
}
private void button1_Click(object sender, EventArgs e)
{
this.Hide();
AddClient client = new AddClient();
client.Show();
}
private void button5_Click(object sender, EventArgs e)
{
this.Hide();
Poch goUser = new Poch();
goUser.Show();
}
private void button6_Click(object sender, EventArgs e)
{
this.Hide();
edpass goUser = new edpass();
goUser.Show();
}
}
}