private void saveBtn_Click(object sender, EventArgs e)
        {
            foreach (DataGridViewRow row in dgvDialogs.Rows)
            {
                // Check Name
                if (!NamingGuidance.CheckDialogName((string)row.Cells[1].Value, true))
                {
                    // Start editing the faulty name cell
                    dgvDialogs.CurrentCell = row.Cells[1];
                    dgvDialogs.BeginEdit(false);
                    return;
                }

                // Check title
                if (!NamingGuidance.CheckCaption((string)row.Cells[2].Value, "Dialog Title", true))
                {
                    // Start editing the faulty name cell
                    dgvDialogs.CurrentCell = row.Cells[2];
                    dgvDialogs.BeginEdit(false);
                    return;
                }
            }

            SelectedDialogs.Clear();

            foreach (LocalDialog d in localDialogs)
            {
                if (d.Selected)
                {
                    // Now set the new Name and Title from the grid.
                    d.Dialog.Name  = d.Name;
                    d.Dialog.Title = d.Title;

                    // Add the dialog to the selected ones.
                    SelectedDialogs.Add(d.Dialog);
                }
            }

            if (SelectedDialogs.Count > 0)
            {
                DialogResult = DialogResult.OK;
            }
            else
            {
                cancelBtn_Click(sender, e);
            }
        }
 private void dgvDialogs_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
 {
     // Check if edited cell is Name or Title
     if (e.ColumnIndex == 1) // Name
     {
         if (!NamingGuidance.CheckDialogName(e.FormattedValue.ToString(), true))
         {
             e.Cancel = true;
         }
     }
     else if (e.ColumnIndex == 2) // Title
     {
         if (!NamingGuidance.CheckCaption(e.FormattedValue.ToString(), "Dialog Title", true))
         {
             e.Cancel = true;
         }
     }
 }
        private void btnOK_Click(object sender, EventArgs e)
        {
            // Check name.
            if (!NamingGuidance.CheckDialogName(tbName.Text.Trim(), true))
            {
                return;
            }

            // Check Title
            if (!NamingGuidance.CheckCaptionFocus(tbTitle, "Dialog title", true))
            {
                return;
            }

            foreach (Module item in moduleCbx.Items.Cast <Module>())
            {
                if (item.Name == moduleCbx.Text)
                {
                    moduleCbx.SelectedItem = item;
                }
            }

            // The name must be unique within the same module

            IList <Cdc.MetaManager.DataAccess.Domain.Dialog> dialogList = dialogService.FindDialogsByNameAndModule(FrontendApplication.Id, moduleCbx.Text, tbName.Text);


            if (dialogList.Count > 0)
            {
                MessageBox.Show("The name of the dialog must be unique within the same module, please change the value for the dialog name!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                tbName.SelectAll();
                tbName.Focus();
                return;
            }



            Module module = moduleCbx.SelectedItem as Module;

            try
            {
                if (module == null)
                {
                    if (string.IsNullOrEmpty(moduleCbx.Text))
                    {
                        MessageBox.Show("You must select or enter a module.");
                        return;
                    }
                    else
                    {
                        module             = new Module();
                        module.Application = FrontendApplication;
                        module.Name        = moduleCbx.Text;

                        module = (Module)modelService.SaveDomainObject(module);

                        PopulateModuleCombobox();

                        foreach (Module item in moduleCbx.Items.Cast <Module>())
                        {
                            if (item.Id == module.Id)
                            {
                                moduleCbx.SelectedItem = item;
                            }
                        }
                    }
                }

                Dialog             = new Dialog();
                Dialog.Name        = tbName.Text.Trim();
                Dialog.Title       = tbTitle.Text.Trim();
                Dialog.CreatorName = tbCreatorName.Text.Trim();
                Dialog.Type        = (DialogType)Enum.Parse(typeof(DialogType), typeCbx.SelectedItem.ToString());

                //Check that Views that are used in create or modify dialogs not is used in other dialogs

                if (Dialog.Type == DialogType.Create || Dialog.Type == DialogType.Modify)
                {
                    long noOfViews = dialogService.CountViewNodes(SelectedView);

                    if (noOfViews > 0)
                    {
                        //We will not allow to use the same view in several dialogs.
                        MessageBox.Show("The view is already used by another dialog. Please, select another view for this dialog!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        tbViewName.SelectAll();
                        tbViewName.Focus();
                        return;
                    }
                }



                // Create Rote ViewNode
                ViewNode rootNode = new Cdc.MetaManager.DataAccess.Domain.ViewNode();
                rootNode.View = SelectedView;
                if (Dialog.Type == DialogType.Overview || Dialog.Type == DialogType.Drilldown)
                {
                    rootNode.Title = "Overview";
                }
                else if (Dialog.Type == DialogType.Create || Dialog.Type == DialogType.Modify || Dialog.Type == DialogType.Find)
                {
                    rootNode.Title = Dialog.Title;
                }
                rootNode.Sequence = 1;
                rootNode.Dialog   = Dialog;
                Dialog.ViewNodes.Add(rootNode);
                Dialog.RootViewNode  = rootNode;
                Dialog.InterfaceView = SelectedView;
                Dialog.Module        = moduleCbx.SelectedItem as Module;

                // Save Dialog
                modelService.MergeSaveDomainObject(Dialog);


                // Check out the dialog
                CheckOutInObject(Dialog, true);

                ContaindDomainObjectIdAndType = new KeyValuePair <Guid, Type>(Dialog.Id, typeof(Dialog));
                DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }