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 { public partial class ChildForm : Form { private readonly ColumnConf[] tableMainColumns = { new ColumnConf(name: "№"), new ColumnConf(name: "Фамилия И.О.", size: 140), new ColumnConf(name: "Пол", size: 80), new ColumnConf(name: "Дата рождения", size: 80), new ColumnConf(name: "Род 1", size: 140), new ColumnConf(name: "Род 2", size: 140) }; private void resetChildTable() { try { var res = FuncDB.ChildTableMain(findBox.Text); this.ResetTable( childGridView, tableMainColumns, res ); } catch (Exception e) { this.ShowError(errorLabel, e.Message); } } private Child selectedChildTable() { try { if (childGridView.SelectedRows.Count != 1) throw new Exception("Ребонок не выбран."); if (int.TryParse((string)childGridView.SelectedRows[0].Cells[0].Value, out int value)) return FuncDB.ChildGetById(value); else throw new Exception("Ошибка в таблице."); } catch (Exception e) { this.ShowError(errorLabel, e.Message); return null; } } private void resetChildCount() { try { lableChildCount.Text = FuncDB.ChildCount(dateTimePicker1.Value).ToString(); lableChildCountMale.Text = FuncDB.ChildCount(dateTimePicker1.Value, true).ToString(); lableChildCountFemale.Text = FuncDB.ChildCount(dateTimePicker1.Value, false).ToString(); } catch (Exception e) { this.ShowError(errorLabel, e.Message); } } public ChildForm() { InitializeComponent(); this.correctUpperMenu(menuStrip, 6); resetChildTable(); dateTimePicker1.Value = DateTime.Now; resetChildCount(); addButton.Enabled = changeButton.Enabled = delButton.Enabled = false; var user = this.GetUser(); if (user == null) return; delButton.Enabled = FuncDB.AccessGetByUserIdFormIdAccessId(user.Id, 6, 1) != null; changeButton.Enabled = FuncDB.AccessGetByUserIdFormIdAccessId(user.Id, 6, 2) != null; addButton.Enabled = FuncDB.AccessGetByUserIdFormIdAccessId(user.Id, 6, 3) != null; } private void addButton_Click(object sender, EventArgs e) { try { var form = new SupportForms.ChildForm(); form.ShowDialog(); if (!form.isCanceled) resetChildTable(); resetChildCount(); } catch (Exception ex) { this.ShowError(errorLabel, ex.Message); } } private void changeButton_Click(object sender, EventArgs e) { try { var form = new SupportForms.ChildForm(selectedChildTable()); form.ShowDialog(); if (!form.isCanceled) resetChildTable(); resetChildCount(); } catch (Exception ex) { this.ShowError(errorLabel, ex.Message); } } private void delButton_Click(object sender, EventArgs e) { try { var res = selectedChildTable(); FuncDB.ChildDelete(res); resetChildTable(); resetChildCount(); } catch (Exception ex) { this.ShowError(errorLabel, ex.Message); } } private void upperMenuClicked(object sender, ToolStripItemClickedEventArgs e) { this.upperMenuClicked((MenuStrip)sender); if (this.GetNextForm() != -1) Close(); } private void button1_Click(object sender, EventArgs e) { resetChildCount(); } private void findBox_TextChanged(object sender, EventArgs e) { this.FindOnChanged(resetChildTable); } private void dropFindButton_Click(object sender, EventArgs e) { findBox.Text = ""; this.FindOnChanged(null); resetChildTable(); } } }