public Admin(string id) { InitializeComponent(); //Получаем имя позователя для приветствия salutationLabel.Text = DBGate.GetSalutation(Properties.Settings.Default.ConnectionString, id); Users users = new Users { Dock = DockStyle.Fill }; usersTab.Controls.Add(users); Students students = new Students { Dock = DockStyle.Fill }; studentsTab.Controls.Add(students); Teachers teachers = new Teachers { Dock = DockStyle.Fill }; teachersTab.Controls.Add(teachers); Reports reports = new Reports(id) { Dock = DockStyle.Fill }; reportsTab.Controls.Add(reports); }
private void Start() { salutationLabel.Text = DBGate.GetSalutation(Properties.Settings.Default.ConnectionString, id); UserControls.Reports reports = new UserControls.Reports(id); reports.Dock = DockStyle.Fill; this.Controls["panel1"].Controls.Add(reports); }
public Teacher(string id) { InitializeComponent(); //Получаем имя позователя для приветствия salutationLabel.Text = DBGate.GetSalutation(Properties.Settings.Default.ConnectionString, id); Students students = new Students { Dock = DockStyle.Fill }; string yearID = DBGate.Scalar(Properties.Settings.Default.ConnectionString, $"select yearID from Teachers where userID = {id}"); string classID = DBGate.Scalar(Properties.Settings.Default.ConnectionString, $"select classID from Teachers where userID = {id}"); students.query = "select ID as 'ID', " + "name as 'Имя', " + "birth as 'Дата рождения', " + "year as 'Год обучения', " + "(select name from Classes where Classes.ID = Students.class) as 'Класс', " + "paySumm as 'Задолженность', " + "activeFlag as 'Питание' " + "from Students " + $"where year = {yearID} and class = {classID}"; students.Controls["panel4"].Controls["addUser"].Enabled = false; students.Controls["panel1"].Controls["deleteStudent"].Enabled = false; students.Start(); ClassPage.Controls.Add(students); }
private void AddUser_Load(object sender, EventArgs e) { string query = "select name from Classes"; classBox.DataSource = DBGate.GetColumnFromDB(Properties.Settings.Default.ConnectionString, query); query = "select name from Years where ID <> '12'"; yearBox.DataSource = DBGate.GetColumnFromDB(Properties.Settings.Default.ConnectionString, query); }
private void button1_Click(object sender, EventArgs e) { if (DBGate.CheckConnection(textBox1.Text)) { MessageBox.Show("Успешно!"); } else { MessageBox.Show("Подключение невозможно. Проверьте правильность ввода."); } }
private void OKClick(object sender, EventArgs e) { string query = $"select count(*) from Users where login = N'{loginBox.Text}' and password = N'{passwordBox.Text}'"; if (DBGate.Scalar(Properties.Settings.Default.ConnectionString, query) != "0") { RunSpecialForm(); } else { MessageBox.Show("Введенная пара логин-пароль отсутствует в базе данных. Проверьте правильность ввода.", "Ошибка ввода.", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
private bool InsertNewRow() { string query = $"insert into Students (name, birth, year, class) " + $"values('{nameBox.Text}', '{birthPicker.Value.ToString()}', '{yearBox.SelectedIndex + 1}', {classBox.SelectedIndex + 1})"; Exception result = DBGate.NonQuery(Properties.Settings.Default.ConnectionString, query); if (result != null) { MessageBox.Show( $"Критическая ошибка при добавлении." + result.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Information); return(false); } return(true); }
private bool InsertNewRow() { string query = $"insert into Users (login, password, name, role) " + $"values('{loginBox.Text}', '{passwordBox.Text}', '{nameBox.Text}', {roleBox.SelectedIndex + 1})"; Exception result = DBGate.NonQuery(Properties.Settings.Default.ConnectionString, query); if (result != null) { MessageBox.Show( $"Критическая ошибка при добавлении. \r\nВведенное имя пользователя уже занято.", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Information); return(false); } return(true); }
private void RunSpecialForm() { string id, role; string queryActive = $"select active from Users where login = N'{loginBox.Text}'"; string queryId = $"select ID from Users where login = N'{loginBox.Text}'"; string queryRole = $"select role from Users where login = N'{loginBox.Text}'"; if (DBGate.Scalar(Properties.Settings.Default.ConnectionString, queryActive) != "True") { MessageBox.Show("Ваша учетная запись заблокирована!"); return; } id = DBGate.Scalar(Properties.Settings.Default.ConnectionString, queryId); role = DBGate.Scalar(Properties.Settings.Default.ConnectionString, queryRole); this.Hide(); switch (role) { default: MessageBox.Show("Неизвестная ошибка, обратитесь к администратору.", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); Environment.Exit(0); break; case "1": new Admin(id).Show(); break; case "2": new Worker(id).Show(); break; case "3": string query = $"select count(*) from Teachers where userID = N'{id}'"; if (DBGate.Scalar(Properties.Settings.Default.ConnectionString, query) != "0") { new Teacher(id).Show(); break; } else { MessageBox.Show("Вы не являетесь классным руководителем, данный функционал вам не доступен. Обратитесь к администратору, если это не так."); this.Show(); break; } } }
private void LoadedStartForm(object sender, EventArgs e) { if (DBGate.CheckConnection(Properties.Settings.Default.ConnectionString)) { return; } else { var result = new DialogResult(); result = MessageBox.Show("Подключение к базе данных невозможно, т.к. отсутствует корректная строка подключения. Ввести строку подключения вручную?", "Подключение данных невозможно.", MessageBoxButtons.YesNo, MessageBoxIcon.Error); if (result == DialogResult.Yes) { GetNewConnectionString(new NewConnection()); } else { MessageBox.Show("Дальнейшая работа невозможна, обратитесь к администратору.", "Закрытие программы.", MessageBoxButtons.OK, MessageBoxIcon.Error); Environment.Exit(0); } } }
private void AddUser_Load(object sender, EventArgs e) { string query = "select name from Roles"; roleBox.DataSource = DBGate.GetColumnFromDB(Properties.Settings.Default.ConnectionString, query); }