Mercurial > pub > bltoolkit
diff Demo/WinForms/Forms/MainForm.cs @ 0:f990fcb411a9
Копия текущей версии из github
author | cin |
---|---|
date | Thu, 27 Mar 2014 21:46:09 +0400 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Demo/WinForms/Forms/MainForm.cs Thu Mar 27 21:46:09 2014 +0400 @@ -0,0 +1,77 @@ +using System; +using System.Windows.Forms; + +using BLToolkit.Demo.ObjectModel; +using BLToolkit.Demo.BusinessLogic; + +namespace BLToolkit.Demo.Forms +{ + public partial class MainForm : Form + { + public MainForm() + { + InitializeComponent(); + + personBinder.List = new PersonManager().SelectAll(); + } + + private void Edit(Person person) + { + EditPersonForm.Edit(person, delegate(Person p) + { + new PersonManager().Update(p); + }); + } + + private void personGridView_CellDoubleClick(object sender, DataGridViewCellEventArgs e) + { + DataGridViewRow row = personGridView.Rows[e.RowIndex]; + + Edit((Person)row.DataBoundItem); + } + + private void edit_Click(object sender, EventArgs e) + { + if (personGridView.CurrentRow != null) + Edit((Person)personGridView.CurrentRow.DataBoundItem); + } + + private void new_Click(object sender, EventArgs e) + { + Person person = EditPersonForm.EditNew(delegate(Person p) + { + new PersonManager().Insert(p); + }); + + if (person != null) + personBinder.List.Add(person); + } + + private void delete_Click(object sender, EventArgs e) + { + if (personGridView.CurrentRow != null) + { + Person person = (Person)personGridView.CurrentRow.DataBoundItem; + + try + { + UseWaitCursor = true; + new PersonManager().Delete(person); + UseWaitCursor = false; + + personBinder.List.Remove(person); + } + catch (Exception ex) + { + UseWaitCursor = false; + MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + } + } + } + + private void exit_Click(object sender, EventArgs e) + { + Close(); + } + } +} \ No newline at end of file