Advertisement
Guest User

Untitled

a guest
Dec 8th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.Data.SqlClient;
  11.  
  12. namespace KCP_lab_3
  13. {
  14. public partial class Form2 : Form
  15. {
  16. private Form1 form_1;
  17.  
  18. public Form2(Form1 form1)
  19. {
  20. InitializeComponent();
  21. this.form_1 = form1;
  22. }
  23.  
  24. private void Form2_Load(object sender, EventArgs e)
  25. {
  26. DataTable dt_user = form_1.Select("Select id_user from [User]");
  27. for (int i = 0; i < dt_user.Rows.Count; i++)
  28. {
  29. comboBox1.Items.Add(dt_user.Rows[i][0].ToString());
  30. }
  31. }
  32.  
  33. private void button1_Click(object sender, EventArgs e)
  34. {
  35. if (textBox1.Text.Length > 0) // проверяем введён ли логин
  36. {
  37. if (textBox2.Text.Length > 0) // проверяем введён ли пароль
  38. { // ищем в базе данных пользователя с такими данными
  39. if (textBox4.Text.Length > 0)
  40. {
  41. DataTable dt_user = form_1.Select("Insert into [User] (id_user, login, password) " +
  42. "values(" + textBox4.Text + ", '" + textBox1.Text + "', '" + textBox2.Text + "')");
  43. textBox1.Clear();
  44. textBox2.Clear();
  45. textBox4.Clear();
  46. MessageBox.Show("пользователь был добавлен в базу данных");
  47. }
  48. else MessageBox.Show("Идентификатор не введен"); //ошибка
  49. }
  50. else MessageBox.Show("Пароль не введен"); // выводим ошибку
  51. }
  52. else MessageBox.Show("Логин не введен"); // выводим ошибку
  53. }
  54.  
  55. private void button2_Click(object sender, EventArgs e)
  56. {
  57. if (comboBox1.Text.Length > 0) // проверяем введён ли логин
  58. {
  59. DataTable dt_user = form_1.Select("Update [User] Set admin=" +
  60. textBox3.Text + " where id_user=" + comboBox1.Text);
  61. MessageBox.Show("Права пользователя были успешно изменены");
  62. }
  63. else MessageBox.Show("не выбран пользователь из списка"); // выводим ошибку
  64. }
  65. }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement