/
denispirit
/
informationSystem
Обзор
Документация
Войти
/
denispirit
/
informationSystem
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
InformationSystem/Form1.cs
193 строки
7 KB
denispirit
Первый коммит. Отправка в репозиторий
29 сен 2025, 10:39
29 сен 2025, 10:39
24ca85c
Код
Авторство
О чём код?
using System; using System.Windows.Forms; namespace InformationSystem { public partial class LoginForm : Form { private Database db = new Database(); // ��������� ������ ��� ������ � �� public LoginForm() { InitializeComponent(); // ������������� ����������� ����� txtPassword.UseSystemPasswordChar = true; // �������� ������� ������ ApplyStyles(); // ��������� ����� ����� ������������� ����������� } private void ApplyStyles() { // ��������� ����� StyleHelper.ApplyStyle(this); this.Text = "���� � �������"; this.Size = new Size(400, 500); this.Padding = new Padding(20); // ������� � ����������� layout SetupLayout(); } private void SetupLayout() { // ������� ������������� ��������������� �������� � ������� ������ � ������ this.Controls.Clear(); // ������� ������� ��� ���������� ��������� TableLayoutPanel mainTable = new TableLayoutPanel(); mainTable.Dock = DockStyle.Fill; mainTable.RowCount = 6; mainTable.ColumnCount = 1; mainTable.Padding = new Padding(10); mainTable.BackColor = Color.Transparent; // ����������� ������ mainTable.RowStyles.Add(new RowStyle(SizeType.Absolute, 60)); // ��������� mainTable.RowStyles.Add(new RowStyle(SizeType.Absolute, 70)); // ����� mainTable.RowStyles.Add(new RowStyle(SizeType.Absolute, 70)); // ������ mainTable.RowStyles.Add(new RowStyle(SizeType.Absolute, 40)); // ������� mainTable.RowStyles.Add(new RowStyle(SizeType.Absolute, 50)); // ������ mainTable.RowStyles.Add(new RowStyle(SizeType.Percent, 100)); // ������������ // ��������� Label titleLabel = new Label(); titleLabel.Text = "���� � �������"; titleLabel.Font = StyleHelper.TitleFont; titleLabel.ForeColor = StyleHelper.PrimaryColor; titleLabel.TextAlign = ContentAlignment.MiddleCenter; titleLabel.Dock = DockStyle.Fill; mainTable.Controls.Add(titleLabel, 0, 0); // ���� ������ Panel loginPanel = CreateInputPanel("�����:", "txtUsername"); mainTable.Controls.Add(loginPanel, 0, 1); // ���� ������ Panel passwordPanel = CreateInputPanel("������:", "txtPassword", true); mainTable.Controls.Add(passwordPanel, 0, 2); // ������� ������ ������ CheckBox chkShowPassword = new CheckBox(); StyleHelper.StyleCheckBox(chkShowPassword); chkShowPassword.Text = "�������� ������"; chkShowPassword.CheckedChanged += chkShowPassword_CheckedChanged; chkShowPassword.Dock = DockStyle.Top; chkShowPassword.Margin = new Padding(0, 10, 0, 0); Panel checkPanel = new Panel(); checkPanel.Dock = DockStyle.Fill; checkPanel.BackColor = Color.Transparent; checkPanel.Controls.Add(chkShowPassword); mainTable.Controls.Add(checkPanel, 0, 3); // ������ ������ Panel buttonPanel = new Panel(); buttonPanel.Dock = DockStyle.Fill; buttonPanel.BackColor = Color.Transparent; Button btnLogin = new Button(); StyleHelper.StyleButton(btnLogin, true); btnLogin.Text = "�����"; btnLogin.Click += btnLogin_Click; btnLogin.Dock = DockStyle.Left; btnLogin.Margin = new Padding(0, 0, 10, 0); Button btnRegister = new Button(); StyleHelper.StyleButton(btnRegister, false); btnRegister.Text = "�����������"; btnRegister.Click += btnRegister_Click; btnRegister.Dock = DockStyle.Right; buttonPanel.Controls.Add(btnRegister); buttonPanel.Controls.Add(btnLogin); mainTable.Controls.Add(buttonPanel, 0, 4); this.Controls.Add(mainTable); } private Panel CreateInputPanel(string labelText, string controlName, bool isPassword = false) { Panel panel = new Panel(); panel.Dock = DockStyle.Fill; panel.BackColor = Color.Transparent; Label label = new Label(); label.Text = labelText; StyleHelper.StyleLabel(label, false); label.Dock = DockStyle.Top; label.Margin = new Padding(0, 0, 0, 5); TextBox textBox = new TextBox(); textBox.Name = controlName; StyleHelper.StyleTextBox(textBox); textBox.Dock = DockStyle.Bottom; if (isPassword) { textBox.UseSystemPasswordChar = true; if (controlName == "txtPassword") txtPassword = textBox; } else { if (controlName == "txtUsername") txtUsername = textBox; } panel.Controls.Add(textBox); panel.Controls.Add(label); return panel; } // ���������� ������� ������ ����� private void btnLogin_Click(object sender, EventArgs e) { // �������� ���������� ����� if (string.IsNullOrWhiteSpace(txtUsername.Text) || string.IsNullOrWhiteSpace(txtPassword.Text)) { MessageBox.Show("������� ����� � ������"); return; } // �������� ������������ � ���� ������ if (db.ValidateUser(txtUsername.Text.Trim(), txtPassword.Text)) { // �������� ID ������������ int userId = db.GetUserId(txtUsername.Text.Trim()); MessageBox.Show("�������� ����!", "�����������", MessageBoxButtons.OK, MessageBoxIcon.Information); // ��������� ������� ����� MainForm mainForm = new MainForm(userId); mainForm.Show(); this.Hide(); // �������� ����� ����� } else { MessageBox.Show("�������� ����� ��� ������", "������", MessageBoxButtons.OK, MessageBoxIcon.Error); txtPassword.Clear(); // ������� ���� ������ txtPassword.Focus(); // ������������� ����� �� ���� ������ } } // ���������� ������� ������ ����������� private void btnRegister_Click(object sender, EventArgs e) { RegisterForm regForm = new RegisterForm(); // ������� ����� ����������� if (regForm.ShowDialog() == DialogResult.OK) // ��������� ��� ��������� ���� { // ����� �������� ����������� ����� ��������� ����� txtUsername.Text = regForm.Username; } } // ���������� ��������� ��������� �������� "�������� ������" private void chkShowPassword_CheckedChanged(object sender, EventArgs e) { CheckBox chk = sender as CheckBox; if (txtPassword != null) txtPassword.UseSystemPasswordChar = !chk.Checked; } } }