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 Diplom_O.DataBase; namespace Diplom_O.SupportForms { public partial class LoginForm : Form { public bool isCanceled = false; private User user = null; public LoginForm(User user = null) { InitializeComponent(); formBox.Items.Clear(); for (var i = 0; i < 8; i++) formBox.Items.Add(FormArray.GetNameString(i)); formBox.SelectedIndex = 0; hideBox.Checked = false; try { if (user != null) { this.user = user; workButton.Text = "Изменить"; loginBox.Text = user.Login; passBox.Text = user.Pass; formBox.SelectedIndex = user.Default; hideBox.Checked = user.Hide; } } catch (Exception e) { this.ShowError(errorLabel, e.Message); workButton.Enabled = false; } } private void workButton_Click(object sender, EventArgs e) { try { var _user = new User(); _user.Login = loginBox.Text; _user.Pass = passBox.Text; _user.Hide = hideBox.Checked; _user.Default = formBox.SelectedIndex; FuncDB.UserCheckValid(_user); if (user == null) FuncDB.UserAdd(_user); else { _user.Id = user.Id; if (FuncDB.AccessGetByUserIdFormIdAccessId(_user.Id, _user.Default, 0) == null) throw new Exception("Необходим сначала доступ к форме."); FuncDB.UserChange(_user); } this.Close(); } catch (Exception ex) { this.ShowError(errorLabel, ex.Message); } } private void canceledButton_Click(object sender, EventArgs e) { isCanceled = true; this.Close(); } } }