Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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 KCP_lab_3
- {
- public partial class Form2 : Form
- {
- private Form1 form_1;
- public Form2(Form1 form1)
- {
- InitializeComponent();
- this.form_1 = form1;
- }
- private void Form2_Load(object sender, EventArgs e)
- {
- DataTable dt_user = form_1.Select("Select id_user from [User]");
- for (int i = 0; i < dt_user.Rows.Count; i++)
- {
- comboBox1.Items.Add(dt_user.Rows[i][0].ToString());
- }
- }
- private void button1_Click(object sender, EventArgs e)
- {
- if (textBox1.Text.Length > 0) // проверяем введён ли логин
- {
- if (textBox2.Text.Length > 0) // проверяем введён ли пароль
- { // ищем в базе данных пользователя с такими данными
- if (textBox4.Text.Length > 0)
- {
- DataTable dt_user = form_1.Select("Insert into [User] (id_user, login, password) " +
- "values(" + textBox4.Text + ", '" + textBox1.Text + "', '" + textBox2.Text + "')");
- textBox1.Clear();
- textBox2.Clear();
- textBox4.Clear();
- MessageBox.Show("пользователь был добавлен в базу данных");
- }
- else MessageBox.Show("Идентификатор не введен"); //ошибка
- }
- else MessageBox.Show("Пароль не введен"); // выводим ошибку
- }
- else MessageBox.Show("Логин не введен"); // выводим ошибку
- }
- private void button2_Click(object sender, EventArgs e)
- {
- if (comboBox1.Text.Length > 0) // проверяем введён ли логин
- {
- DataTable dt_user = form_1.Select("Update [User] Set admin=" +
- textBox3.Text + " where id_user=" + comboBox1.Text);
- MessageBox.Show("Права пользователя были успешно изменены");
- }
- else MessageBox.Show("не выбран пользователь из списка"); // выводим ошибку
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement