Users.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. using Servise.Classes;
  2. using Servise.Forms.User;
  3. using System;
  4. using System.Data;
  5. using System.Data.SqlClient;
  6. using System.Windows.Forms;
  7. namespace Servise.Forms
  8. {
  9. public partial class Users : Form
  10. {
  11. DataBase conect = new DataBase();
  12. public Users()
  13. {
  14. InitializeComponent();
  15. }
  16. private void Users_Load(object sender, EventArgs e)
  17. {
  18. textName.ReadOnly = true;
  19. textSurname.ReadOnly = true;
  20. textEmail.ReadOnly = true;
  21. maskedPhone.ReadOnly = true;
  22. textLogin.ReadOnly = true;
  23. textPatronymic.ReadOnly = true;
  24. conect.openConect();
  25. SqlCommand sql = new SqlCommand("Select name From employees where login='" + UserInform.Login + "'", conect.getConect());
  26. textName.Text = sql.ExecuteScalar().ToString();
  27. sql = new SqlCommand("Select surname From employees where login='" + UserInform.Login + "'", conect.getConect());
  28. textSurname.Text = sql.ExecuteScalar().ToString();
  29. sql = new SqlCommand("Select patronymic From employees where login='" + UserInform.Login + "'", conect.getConect());
  30. textPatronymic.Text = sql.ExecuteScalar().ToString();
  31. sql = new SqlCommand("Select email From employees where login='" + UserInform.Login + "'", conect.getConect());
  32. textEmail.Text = sql.ExecuteScalar().ToString();
  33. sql = new SqlCommand("Select phone From employees where login='" + UserInform.Login + "'", conect.getConect());
  34. maskedPhone.Text = sql.ExecuteScalar().ToString();
  35. sql = new SqlCommand("Select login From employees where login='" + UserInform.Login + "'", conect.getConect());
  36. textLogin.Text = sql.ExecuteScalar().ToString();
  37. }
  38. private void button4_Click(object sender, EventArgs e)
  39. {
  40. textName.ReadOnly = false;
  41. textSurname.ReadOnly = false;
  42. textEmail.ReadOnly = false;
  43. maskedPhone.ReadOnly = false;
  44. textLogin.ReadOnly = false;
  45. textPatronymic.ReadOnly = false;
  46. }
  47. private void button3_Click(object sender, EventArgs e)
  48. {
  49. conect.openConect(); ;
  50. string n = textName.Text;
  51. string s = textSurname.Text;
  52. string p = textPatronymic.Text;
  53. string ph = maskedPhone.Text;
  54. string em = textEmail.Text;
  55. string l = textLogin.Text.Trim();
  56. string query = "Select *from employees where login = '" + l + "'";
  57. SqlDataAdapter sda = new SqlDataAdapter(query, conect.getConect());
  58. DataTable dtbl = new DataTable();
  59. sda.Fill(dtbl);
  60. if (dtbl.Rows.Count == 0)
  61. {
  62. var indert = "update employees set name = '" + n + "'," + "surname= '" + s + "'," + "patronymic= '" + p + "'," + "phone= '" + ph + "'," + "email= '" + em + "'," + "login= '" + l + "' where login ='" + UserInform.Login + "'";
  63. var command = new SqlCommand(indert, conect.getConect());
  64. command.ExecuteNonQuery();
  65. UserInform.Login = textLogin.Text.Trim();
  66. textName.ReadOnly = true;
  67. textSurname.ReadOnly = true;
  68. textEmail.ReadOnly = true;
  69. maskedPhone.ReadOnly = true;
  70. textLogin.ReadOnly = true;
  71. textPatronymic.ReadOnly = true;
  72. }
  73. else
  74. {
  75. MessageBox.Show("Логин занят");
  76. }
  77. conect.closeConect();
  78. conect.closeConect();
  79. }
  80. private void Users_FormClosing(object sender, FormClosedEventArgs e)
  81. {
  82. Application.Exit();
  83. }
  84. /// <summary>
  85. /// Кнопки для переходов на соответствующие страницы
  86. /// </summary>
  87. /// <param name="sender"></param>
  88. /// <param name="e"></param>
  89. private void button2_Click(object sender, EventArgs e)
  90. {
  91. this.Hide();
  92. AddZac goUser = new AddZac();
  93. goUser.Show();
  94. }
  95. private void button1_Click(object sender, EventArgs e)
  96. {
  97. this.Hide();
  98. AddClient client = new AddClient();
  99. client.Show();
  100. }
  101. private void button5_Click(object sender, EventArgs e)
  102. {
  103. this.Hide();
  104. Poch goUser = new Poch();
  105. goUser.Show();
  106. }
  107. private void button6_Click(object sender, EventArgs e)
  108. {
  109. this.Hide();
  110. edpass goUser = new edpass();
  111. goUser.Show();
  112. }
  113. }
  114. }