private void contextItem_Properties_Click(object sender, EventArgs e)
        {
            if (_contextItem is FieldListViewItem)
            {
                Field            oField = ((FieldListViewItem)_contextItem).Field;
                FormPropertyGrid dlg    = new FormPropertyGrid(
                    new Field(oField));

                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    Field nField = dlg.SelectedObject as Field;
                    if (!oField.Equals(nField))
                    {
                        if (AlterTable == null)
                        {
                            MessageBox.Show("Change properties is not implemented for this feature...");
                            return;
                        }

                        if (!AlterTable.AlterTable(_exObject.Name, oField, nField))
                        {
                            MessageBox.Show("ERROR: " + ((AlterTable is IDatabase) ? ((IDatabase)AlterTable).lastErrorMsg : ""));
                            return;
                        }

                        this.OnShow();
                    }
                }
            }
        }
        private void contextItem_ImportFields_Click(object sender, EventArgs e)
        {
            if (AlterTable == null)
            {
                MessageBox.Show("Change properties is not implemented for this feature...");
                return;
            }
            if (_exObject == null || !(_exObject.Object is ITableClass))
            {
                return;
            }

            List <ExplorerDialogFilter> filters = new List <ExplorerDialogFilter>();

            filters.Add(new OpenFeatureclassFilter());

            ExplorerDialog dlg = new ExplorerDialog("Open Featureclass", filters, true);

            dlg.MulitSelection = false;

            if (dlg.ShowDialog() == DialogResult.OK &&
                dlg.ExplorerObjects != null &&
                dlg.ExplorerObjects.Count == 1 &&
                dlg.ExplorerObjects[0].Object is ITableClass)
            {
                ITableClass tcFrom = dlg.ExplorerObjects[0].Object as ITableClass;
                ITableClass tcTo   = _exObject.Object as ITableClass;

                FormSelectFields selDlg = new FormSelectFields(tcFrom, tcTo);
                if (selDlg.ShowDialog() == DialogResult.OK)
                {
                    foreach (IField field in selDlg.SelectedFields)
                    {
                        if (!AlterTable.AlterTable(_exObject.Name, null, new Field(field)))
                        {
                            MessageBox.Show("ERROR :" + ((AlterTable is IDatabase) ? ((IDatabase)AlterTable).lastErrorMsg : ""));
                            break;
                        }
                    }
                    this.OnShow();
                }
            }
        }
        private void contextItem_Remove_Click(object sender, EventArgs e)
        {
            if (AlterTable == null)
            {
                MessageBox.Show("Change properties is not implemented for this feature...");
                return;
            }

            foreach (ListViewItem item in listView1.SelectedItems)
            {
                if (!(item is FieldListViewItem))
                {
                    continue;
                }
                Field oField = ((FieldListViewItem)item).Field;

                if (!AlterTable.AlterTable(_exObject.Name, oField, null))
                {
                    MessageBox.Show("ERROR :" + ((AlterTable is IDatabase) ? ((IDatabase)AlterTable).lastErrorMsg : ""));
                    break;
                }
            }
            this.OnShow();
        }
        private void contextItem_AddField_Click(object sender, EventArgs e)
        {
            Field            nField = new Field("NewField", FieldType.String);
            FormPropertyGrid dlg    = new FormPropertyGrid(nField);

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                nField = dlg.SelectedObject as Field;

                if (AlterTable == null)
                {
                    MessageBox.Show("Change properties is not implemented for this feature...");
                    return;
                }

                if (!AlterTable.AlterTable(_exObject.Name, null, nField))
                {
                    MessageBox.Show("ERROR: " + ((AlterTable is IDatabase) ? ((IDatabase)AlterTable).lastErrorMsg : ""));
                    return;
                }

                this.OnShow();
            }
        }
Ejemplo n.º 5
0
        private static (string, ColumnsCollection) AlterColumns(ColumnsCollection columns, AlterTable alterTable)
        {
            var table = alterTable.Table;

            foreach (var alterTableStatement in alterTable.DdlAlterTableStatements)
            {
                switch (alterTableStatement)
                {
                case AddColumn a:
                    columns.Add(a.ColumnDefinition);

                    break;

                case DropColumn d:
                    if (!columns.Remove(d.Column))
                    {
                        throw new ArgumentException($"Column '{alterTable.Table}.{d.Column}' does not exist");
                    }

                    break;

                case AlterColumn a:
                    if (!columns.Alter(a.Column, a.AlterColumnAction))
                    {
                        throw new ArgumentException($"Column '{alterTable.Table}.{a.Column}' does not exist");
                    }

                    break;

                case RenameColumn r:
                    if (!columns.Rename(r.Column, r.NewName))
                    {
                        throw new ArgumentException($"Column '{alterTable.Table}.{r.Column}' does not exist");
                    }

                    break;

                case RenameTable r:
                    table = r.NewName;

                    break;

                case AddConstraint a:
                    if (a.ConstraintDefinition.ColumnConstraint is PrimaryKeyConstraint p)
                    {
                        columns.AddConstraint(a.ConstraintDefinition);
                    }

                    break;

                case DropConstraint d:
                    columns.DropConstraint(table, d.Identifier);

                    break;
                }
            }

            return(table, columns);
        }
Ejemplo n.º 6
0
        public Expression GetNode(ExpressionParser parser)
        {
            Lexem      lex = parser.Collection.CurrentLexem();
            Expression res = null;

            if (lex.LexemType == LexType.Command)
            {
                string lowerLexem = lex.LexemText.ToLower();
                if (ParserUtils.ParseCommandPhrase(parser.Collection, "create view", false, false))
                {
                    res = new CreateView();
                }
                if (ParserUtils.ParseCommandPhrase(parser.Collection, "create table", false, false))
                {
                    res = new CreateTable();
                }
                if (res == null && ParserUtils.ParseCommandPhrase(parser.Collection, "alter table", false, false))
                {
                    res = new AlterTable();
                }
                if (res == null && ParserUtils.ParseCommandPhrase(parser.Collection, "drop table", false, false))
                {
                    res = new DropTable();
                }
                if (res == null && ParserUtils.ParseCommandPhrase(parser.Collection, "drop index", false, false))
                {
                    res = new DropIndex();
                }
                if (res == null && (ParserUtils.ParseCommandPhrase(parser.Collection, "create unique index", false, false) ||
                                    ParserUtils.ParseCommandPhrase(parser.Collection, "create index", false, false)))
                {
                    res = new CreateIndex();
                }
                if (res == null)
                {
                    if (parser.Collection.GetNext() != null && parser.Collection.GetNext().IsSkobraOpen())
                    {
                        switch (lowerLexem)
                        {
                        case "count":
                            res = new CountExpr();
                            break;

                        case "sum":
                            res = new SumExpr();
                            break;

                        case "min":
                            res = new MinExpr();
                            break;

                        case "max":
                            res = new MaxExpr();
                            break;

                        case "avg":
                            res = new AvgExpr();
                            break;

                        case "lastinsertrowid":
                            res = new LastInsertRowidExpr();
                            break;

                        case "exists":
                            res = new ExistsExpr();
                            break;

                        case "any":
                            res = new AnyExpr();
                            break;
                        }
                    }

                    switch (lowerLexem)
                    {
                    case "between":    //не функция
                        res = new Between();
                        break;

                    case "select":
                        res = new SelectExpresion();
                        break;

                    case "update":
                        res = new UpdateStatement();
                        break;

                    case "insert":
                        res = new InsertStatement();
                        break;

                    case "delete":
                        res = new DeleteStatement();
                        break;
                    }
                }
            }
            if (res != null)
            {
                return(res);
            }
            return(res);
        }
Ejemplo n.º 7
0
        private async void testToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var node = (TreeNode)this.menuElements.Tag;

            if (node == null)
            {
                return;
            }
            var parent = (TreeNode)node.Parent;

            if (parent == null)
            {
                return;
            }
            if (parent.Text.Equals("TABLES"))
            {
                var table = this.controller.datab.Tables.Find(x => x.TableName.Equals(node.Text));
                if (table == null)
                {
                    return;
                }
                this.AlterTable = new AlterTable(table, await this.controller.GetSQliteConecction());
                this.AlterTable.ShowDialog();
            }
            else if (parent.Text.Equals("VIEWS"))
            {
                string querys  = $"select * from sqlite_master where name = '{node.Text}' and type = 'view'";
                var    results = await this.controller.Consulta(querys);

                var c = $"drop view {node.Text} ; \n \n";

                while (results.Read())
                {
                    c += results["sql"].ToString();
                }
                this.CreateView = new CreateView(false, c);
                if (this.CreateView.ShowDialog() == DialogResult.OK)
                {
                    try
                    {
                        var query  = this.CreateView.Sql;
                        var result = await this.controller.ExecuteConsult(query);

                        if (result == 0)
                        {
                            this.treeViewDataConecction.Nodes.Clear();
                            var nodes = (await this.controller.GethTreeNodes()).ToArray();
                            this.treeViewDataConecction.Nodes.AddRange(nodes);
                            MessageBox.Show("The view was edited suscefully");
                        }
                        else
                        {
                            MessageBox.Show("Not was edited the view");
                        }
                    }
                    catch (Exception ews)
                    {
                        MessageBox.Show("Internal error: \n" + ews.Message);
                    }
                }
            }
            else if (parent.Text.Equals("TRIGGERS"))
            {
                string querys  = $"select * from sqlite_master where name = '{node.Text}' and type = 'trigger'";
                var    results = await this.controller.Consulta(querys);

                var c    = "";
                var drop = $"drop trigger {node.Text} ; \n \n";

                while (results.Read())
                {
                    c += results["sql"].ToString();
                }
                this.manualQuerys.Text = c;
                this.AlterTrigger      = new AlterTrigger(c);
                if (this.AlterTrigger.ShowDialog() == DialogResult.OK)
                {
                    try
                    {
                        var query = this.AlterTrigger.Sql;
                        await this.controller.ExecuteConsult(drop);

                        var result = await this.controller.ExecuteConsult(query);

                        if (result == 0)
                        {
                            this.treeViewDataConecction.Nodes.Clear();
                            var nodes = (await this.controller.GethTreeNodes()).ToArray();
                            this.treeViewDataConecction.Nodes.AddRange(nodes);
                            MessageBox.Show("The trigger was edited suscefully");
                        }
                        else
                        {
                            MessageBox.Show("Not was edited the view");
                        }
                    }
                    catch (Exception ews)
                    {
                        MessageBox.Show("Internal error: \n" + ews.Message);
                    }
                }
            }
            else
            {
            }
        }
Ejemplo n.º 8
0
        public bool CriarOuAlteraFormularioTable()
        {
            var context = new MainContext();

            var json = @"{
    'name': 'decisionpadrao',
    'title': 'DecisionPadrao',
    'internal': false,
    'fields': [
        {
            'name': 'nf',
            'type': 'Integer',
            'label': 'NF',
            'size': '100%',
            'order': 0,
            'required': false,
            'validationRegex': '',
            'mask': '0',
            'appWorkflow': true,
            'isBreakLine': false
        },
        {
            'name': 'valor_solicitado_r',
            'type': 'Double',
            'label': 'Valor Solicitado R$',
            'size': '100%',
            'order': 1,
            'required': false,
            'validationRegex': '',
            'mask': '2',
            'appWorkflow': true,
            'isBreakLine': false
        },
        {
            'name': 'valor_aprovado_r',
            'type': 'Double',
            'label': 'Valor Aprovado (R$)',
            'size': '100%',
            'order': 2,
            'required': false,
            'validationRegex': '',
            'mask': '2',
            'appWorkflow': true,
            'isBreakLine': false
        },
        {
            'name': 'observacao',
            'type': 'String',
            'label': 'Observacao',
            'size': '100%',
            'order': 3,
            'required': false,
            'validationRegex': '',
            'mask': '',
            'appWorkflow': true,
            'isBreakLine': false
        },
        {
            'name': 'campo01',
            'type': 'String',
            'label': 'CAMPO01',
            'size': '50%',
            'order': 4,
            'required': false,
            'validationRegex': '',
            'mask': '',
            'appWorkflow': true,
            'isBreakLine': false
        },
        {
            'name': 'campo02',
            'type': 'String',
            'label': 'CAMPO02',
            'size': '50%',
            'order': 5,
            'required': false,
            'validationRegex': '',
            'mask': '',
            'appWorkflow': true,
            'isBreakLine': false
        },
        {
            'name': 'campo03',
            'type': 'String',
            'label': 'CAMPO03',
            'size': '50%',
            'order': 6,
            'required': false,
            'validationRegex': '',
            'mask': '',
            'appWorkflow': true,
            'isBreakLine': false
        },
        {
            'name': 'campo04',
            'type': 'String',
            'label': 'CAMPO04',
            'size': '100%',
            'order': 7,
            'required': false,
            'validationRegex': '',
            'mask': '',
            'appWorkflow': true,
            'isBreakLine': false
        },
        {
            'name': 'campo05',
            'type': 'String',
            'label': 'CAMPO05',
            'size': '50%',
            'order': 8,
            'required': false,
            'validationRegex': '',
            'mask': '',
            'appWorkflow': true,
            'isBreakLine': false
        },
        {
            'name': 'campo06',
            'type': 'String',
            'label': 'CAMPO06',
            'size': '50%',
            'order': 9,
            'required': false,
            'validationRegex': '',
            'mask': '',
            'appWorkflow': true,
            'isBreakLine': false
        },
        {
            'name': 'campo07',
            'type': 'String',
            'label': 'CAMPO07',
            'size': '50%',
            'order': 10,
            'required': false,
            'validationRegex': '',
            'mask': '',
            'appWorkflow': true,
            'isBreakLine': false
        },
        {
            'name': 'campo08',
            'type': 'String',
            'label': 'CAMPO08',
            'size': '50%',
            'order': 11,
            'required': false,
            'validationRegex': '',
            'mask': '',
            'appWorkflow': true,
            'isBreakLine': false
        },
        {
            'name': 'campo09',
            'type': 'String',
            'label': 'CAMPO09',
            'size': '50%',
            'order': 12,
            'required': false,
            'validationRegex': '',
            'mask': '',
            'appWorkflow': true,
            'isBreakLine': false
        },
        {
            'name': 'campo10',
            'type': 'String',
            'label': 'CAMPO10',
            'size': '50%',
            'order': 13,
            'required': false,
            'validationRegex': '',
            'mask': '',
            'appWorkflow': true,
            'isBreakLine': false
        },
        {
            'name': 'campo11',
            'type': 'String',
            'label': 'CAMPO11',
            'size': '50%',
            'order': 14,
            'required': false,
            'validationRegex': '',
            'mask': '',
            'appWorkflow': true,
            'isBreakLine': false
        },
        {
            'name': 'campo12',
            'type': 'String',
            'label': 'CAMPO12',
            'size': '50%',
            'order': 15,
            'required': false,
            'validationRegex': '',
            'mask': '',
            'appWorkflow': true,
            'isBreakLine': false
        },
        {
            'name': 'campo13',
            'type': 'String',
            'label': 'CAMPO13',
            'size': '50%',
            'order': 16,
            'required': false,
            'validationRegex': '',
            'mask': '',
            'appWorkflow': true,
            'isBreakLine': false
        },
        {
            'name': 'campo14',
            'type': 'String',
            'label': 'CAMPO14',
            'size': '50%',
            'order': 17,
            'required': false,
            'validationRegex': '',
            'mask': '',
            'appWorkflow': true,
            'isBreakLine': false
        },
        {
            'name': 'campo15',
            'type': 'String',
            'label': 'CAMPO15',
            'size': '50%',
            'order': 18,
            'required': false,
            'validationRegex': '',
            'mask': '',
            'appWorkflow': true,
            'isBreakLine': false
        },
{
            'name': 'campo16',
            'type': 'String',
            'label': 'CAMPO15',
            'size': '50%',
            'order': 18,
            'required': false,
            'validationRegex': '',
            'mask': '',
            'appWorkflow': true,
            'isBreakLine': false
        },
{
            'name': 'campo17',
            'type': 'String',
            'label': 'CAMPO15',
            'size': '50%',
            'order': 18,
            'required': false,
            'validationRegex': '',
            'mask': '',
            'appWorkflow': true,
            'isBreakLine': false
        },
{
            'name': 'campo18',
            'type': 'String',
            'label': 'CAMPO15',
            'size': '50%',
            'order': 18,
            'required': false,
            'validationRegex': '',
            'mask': '',
            'appWorkflow': true,
            'isBreakLine': false
        }
    ]
}";


            var tableJson = JsonConvert.DeserializeObject <Formulario>(json);


            var schemaProvider = context.DataProvider.GetSchemaProvider();

            var schema = schemaProvider.GetSchema(context, new GetSchemaOptions());

            var tableScheme = schema.Tables.Where(c => c.TableName == tableJson.Name).FirstOrDefault();

            var comandoRealizadoComSucesso = true;

            if (tableScheme == null)
            {
                TableClass tableClass  = new TableClass(tableJson.Name, tableJson.Fields);
                var        createTable = tableClass.GenerateScript();
                comandoRealizadoComSucesso = context.Execute(createTable) > 0;
            }
            else
            {
                List <Campos> camposNovos = new List <Campos>();
                foreach (var field in tableJson.Fields)
                {
                    if (!tableScheme.Columns.Where(c => c.ColumnName == field.Name).Any())
                    {
                        camposNovos.Add(field);
                    }
                }

                if (camposNovos.Count > 0)
                {
                    var AltersTable = new AlterTable(tableJson.Name, camposNovos).GenerateScript();
                    comandoRealizadoComSucesso = context.Execute(AltersTable) > 0;
                }
            }

            return(comandoRealizadoComSucesso);
        }