using AccountsContracts.BindingModels; using AccountsContracts.BusinessLogicContracts; using AccountsContracts.ViewModels; using ControlsLibraryNet60.Core; using ControlsLibraryNet60.Models; 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; namespace AccountsApp { public partial class FormMain : Form { private IAccountLogic _logic; public FormMain(IAccountLogic logic) { InitializeComponent(); _logic = logic; controlDataTable.LoadColumns(new List { new DataTableColumnConfig { ColumnHeader = "", PropertyName = "Id", Visible = false, Width = 10}, new DataTableColumnConfig { ColumnHeader = "Логин", PropertyName = "Login", Visible = true, Width = 200}, new DataTableColumnConfig { ColumnHeader = "Выбранный интерес", PropertyName = "InterestName", Visible = true, Width = 200}, new DataTableColumnConfig { ColumnHeader = "Email", PropertyName = "Email", Visible = true, Width = 200}, }); } private void создатьToolStripMenuItem_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormAccount)); if (service is FormAccount form) { if (form.ShowDialog() == DialogResult.OK) { LoadData(); } } } private void интересыToolStripMenuItem_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormInterests)); if (service is FormInterests form) { form.ShowDialog(); } } private void FormMain_Load(object sender, EventArgs e) { LoadData(); } private void LoadData() { controlDataTable.Clear(); var accounts = _logic.ReadList(null); if (accounts != null) { controlDataTable.AddTable(accounts); } } private void редактироватьToolStripMenuItem_Click(object sender, EventArgs e) { var service = Program.ServiceProvider?.GetService(typeof(FormAccount)); if (service is FormAccount form) { form.Id = controlDataTable.GetSelectedObject().Id; if (form.ShowDialog() == DialogResult.OK) { LoadData(); } } } private void удалитьToolStripMenuItem_Click(object sender, EventArgs e) { if (MessageBox.Show("Удалить запись?", "", MessageBoxButtons.YesNo) == DialogResult.Yes) { if (_logic.Delete(new AccountBindingModel { Id = controlDataTable.GetSelectedObject().Id })) { LoadData(); } } } } }