private void btnEditCommentary_ItemClick(object sender, ItemClickEventArgs e)
 {
     using (var dlg = new CommentaryDialog(Commentary)) {
         if (dlg.ShowDialog() == DialogResult.OK)
         {
             if (!String.IsNullOrEmpty(Commentary.Title))
             {
                 Commentary.Save();
                 uow.CommitChanges();
             }
         }
     }
 }
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            ConnectionHelper.Connect();

            int commentaryOid = -1;

            using (var uow = new UnitOfWork()) {
                if (!new XPQuery <Commentary>(uow).Any())
                {
                    var commentary = new Commentary(uow)
                    {
                        Abbreviation = String.Empty,
                        Information  = String.Empty,
                        Version      = 4,
                        Title        = String.Empty
                    };

                    using (var dlg = new CommentaryDialog(commentary)) {
                        if (dlg.ShowDialog() == DialogResult.OK)
                        {
                            commentary.Save();
                            uow.CommitChanges();

                            commentaryOid = commentary.Oid;
                        }
                        else
                        {
                            return;
                        }
                    }
                }
                else
                {
                    using (var dlg = new ChooseCommentary()) {
                        if (dlg.ShowDialog() == DialogResult.OK)
                        {
                            commentaryOid = dlg.Commentary.Oid;
                        }
                        else
                        {
                            return;
                        }
                    }
                }
            }

            Application.Run(new MainForm(commentaryOid));
        }
        private void btnAddNew_Click(object sender, EventArgs e)
        {
            var commentary = new Commentary(uow)
            {
                Abbreviation = String.Empty,
                Information  = String.Empty,
                Version      = 4,
                Title        = String.Empty
            };

            using (var dlg = new CommentaryDialog(commentary)) {
                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    if (!String.IsNullOrEmpty(commentary.Title))
                    {
                        commentary.Save();
                        uow.CommitChanges();

                        grid.DataSource = new XPQuery <Commentary>(uow).ToList();
                        view.BestFitColumns();
                    }
                }
            }
        }