Пример #1
0
        private void buttonOk_Click(object sender, EventArgs e)
        {
            string name;

            switch (EditType)
            {
            case EditTypes.CustomMethod:
                ArchAngel.Providers.CodeProvider.DotNet.Function codeMethod;

                try
                {
                    if (!CustomFunction.CodeMethodIsValid(syntaxEditor1.Text, out name, out codeMethod))
                    {
                        MessageBox.Show(this, "The code is not valid. It has an error.", "Invalid code", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(this, "The code is not valid. It has an error.", "Invalid code", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                if (CustomMethod == null)
                {
                    CustomMethod = new CustomFunction(name, syntaxEditor1.Text);
                }
                else
                {
                    CustomMethod.Name       = name;
                    CustomMethod.UserString = syntaxEditor1.Text;
                }
                CustomMethod.CodeFunction      = codeMethod;
                CustomMethod.AutoAddToEntities = checkBoxAutoAddToEntities.Checked;
                break;

            case EditTypes.CustomProperty:

                ArchAngel.Providers.CodeProvider.DotNet.Property codeProperty;

                try
                {
                    if (!CustomProperty.CodePropertyIsValid(syntaxEditor1.Text, out name, out codeProperty))
                    {
                        MessageBox.Show(this, "The code is not valid. It has an error.", "Invalid code", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(this, "The code is not valid. It has an error.", "Invalid code", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                if (CustomProperty == null)
                {
                    CustomProperty = new CustomProperty(name, syntaxEditor1.Text);
                }
                else
                {
                    CustomProperty.Name       = name;
                    CustomProperty.UserString = syntaxEditor1.Text;
                }
                CustomProperty.CodeProperty      = codeProperty;
                CustomProperty.AutoAddToEntities = checkBoxAutoAddToEntities.Checked;
                break;

            default:
                throw new NotImplementedException("EditType not handled yet in buttonOk_Click(): " + EditType.ToString());
            }
            this.DialogResult = DialogResult.OK;
            this.Close();
        }