Example #1
0
 private void addMenuItem_Click(object sender, EventArgs __)
 {
     var numberForm = new NumberForm();
     ShowEditForm(numberForm, () =>
         messagesDataSet.Numbers.AddNumbersRow(
             numberForm.Number, numberForm.MessagesRow));
 }
Example #2
0
        private void editMenuItem_Click(object sender, EventArgs __)
        {
            var current = GetCurrentRow();

            if (current == null)
            {
                return;
            }

            var numberForm = new NumberForm() { Number = current.Number, MessageId = current.MessageId };

            ShowEditForm(numberForm, () =>
            {
                current.Number = numberForm.Number;
                current.MessageId = numberForm.MessageId;
            });
        }
Example #3
0
        private void ShowEditForm(NumberForm numberForm, Action method)
        {
            numberForm.Closing += (_, args) =>
            {
                if (numberForm.DialogResult != DialogResult.OK)
                {
                    return;
                }

                try
                {
                    method();
                    CommitChanges();
                }
                catch (Exception e)
                {
                    MessageBox.Show(String.Format("Error {0}", e.GetType()), "Error",
                        MessageBoxButtons.OK, MessageBoxIcon.Hand,
                        MessageBoxDefaultButton.Button1);
                    args.Cancel = true;
                }
            };

            numberForm.ShowDialog();
        }