Ejemplo n.º 1
0
        public void AddValues(List<MetaData> metadata,string tab,string transid)
        {
            string redo = "";
            var cantidad = 0;
            string undo = "";
             string _connectionString = "Server=CARLOSV;Database= "+dbc.database+";Trusted_Connection=True;MultipleActiveResultSets=True;";

            var rowlog = new MetaDataParser().GetRowLogContentsCero(dbc.database, tab, tipo, transid);

            var converter = new RowLogConversions();

            List<string> valores;
            for (int i = 0; i < listView3.Items.Count; i++)
            {
                if (listView3.Items[i].SubItems[0].Text == "LOP_INSERT_ROWS")
                    anyinsert = listView3.Items[i].SubItems[1].Text;
            }
            for (int i = 0; i < rowlog.Count; i++)
            {
                valores = new List<string>();

                if (tipo == "LOP_MODIFY_ROW")
                {
                    var rowlog1 = new MetaDataParser().GetRowLogContentsCero(dbc.database, tab, "LOP_INSERT_ROWS",anyinsert);
                    cantidad = RowLogConversions.CantidadLongitudFija(rowlog1[0], metadata);
                }

                var values = converter.ParseRowLogContents(rowlog[i], metadata,tipo,cantidad);

                if (values.Count > 0)
                {
                    for (int j = 0; j < values.Count; j++)
                        valores.Add(values[j]);

                    for (int j = 0; j < values.Count; j++)
                    {
                        listView1.Items[j].SubItems[2].Text = values.ElementAt(j);

                    }

                    if (tipo == "LOP_DELETE_ROWS")
                    {
                        redo = "";
                        undo = "";

                        redo += "INSERT INTO " + dbc.database + " VALUES(";
                        undo += "DELETE FROM " + dbc.database + " WHERE ";
                        for (int k = 0; k < values.Count; k++)
                        {
                            if (metadata[k].Type == ColumnType.Char || metadata[k].Type == ColumnType.VarChar)
                            {
                                redo += " '" + values.ElementAt(k) + "'";
                                undo += metadata.ElementAt(k).ColumnName + " = '" + values.ElementAt(k) + "'";
                            }
                            else
                            {
                                redo += " " + values.ElementAt(k);
                                undo += metadata.ElementAt(k).ColumnName + " = " + values.ElementAt(k);
                            }
                            if (k < values.Count - 1)
                            {
                                redo += ",";
                                undo += " AND ";
                            }
                            if (k == values.Count - 1)
                            {
                                redo += ");";
                                undo += ";";
                            }
                        }

                        richTextBox1.Text = redo;
                        richTextBox2.Text = undo;

                    }
                    else if (tipo == "LOP_INSERT_ROWS")
                    {
                        redo = "";
                        undo = "";

                        redo += "INSERT INTO " + dbc.database + " VALUES(";
                        undo += "DELETE FROM " + dbc.database + " WHERE ";
                        for (int k = 0; k < values.Count; k++)
                        {
                            if (metadata[k].Type == ColumnType.Char || metadata[k].Type == ColumnType.VarChar)
                            {
                                redo += " '" + values.ElementAt(k) + "'";
                                undo += metadata.ElementAt(k).ColumnName + " = '" + values.ElementAt(k) + "'";
                            }
                            else
                            {
                                redo += " " + values.ElementAt(k);
                                undo += metadata.ElementAt(k).ColumnName + " = " + values.ElementAt(k);
                            }
                            if (k < values.Count - 1)
                            {
                                redo += ",";
                                undo += " AND ";
                            }
                            if (k == values.Count - 1)
                            {
                                redo += ");";
                                undo += ";";
                            }
                        }

                        richTextBox1.Text = undo;
                        richTextBox2.Text = redo;
                    }
                    else if (tipo == "LOP_MODIFY_ROW")
                    {

                        undoupdate = "";
                        redoupdate = " WHERE ";

                        undoupdate += "UPDATE " + dbc.database + " SET ";
                        for (int k = 0; k < values.Count; k++)
                        {
                            if (metadata[k].Type == ColumnType.Char || metadata[k].Type == ColumnType.VarChar)
                            {

                                undoupdate += metadata.ElementAt(k).ColumnName + " = '" + values.ElementAt(k) + "'";
                                redoupdate += metadata.ElementAt(k).ColumnName + " = '" + values.ElementAt(k) + "'";

                            }
                            else
                            {

                                undoupdate += metadata.ElementAt(k).ColumnName + " = " + values.ElementAt(k);
                                redoupdate += metadata.ElementAt(k).ColumnName + " = " + values.ElementAt(k);
                            }
                            if (k < values.Count - 1)
                            {

                                undoupdate += " AND ";
                                redoupdate += " AND ";
                            }
                            if (k == values.Count - 1)
                            {

                               redoupdate += ";";
                            }
                        }

                        richTextBox1.Text = undoupdate;

                    }
                }
            }

            if (tipo == "LOP_MODIFY_ROW")
            {
               AddAfter(metadata,tab,transid);
            }
        }
Ejemplo n.º 2
0
        public void AddMetaData(string table, string transid)
        {
            var metadata = new MetaDataParser().GetMetadata(database, table);

            for (int i = 0, x = 0; i < metadata.Count - x; i++)
            {
                if (metadata.ElementAt(i).Type == ColumnType.VarChar)
                {
                    var value = metadata.ElementAt(i);
                    metadata.RemoveAt(i);
                    metadata.Add(value);
                    i = -1;
                    x++;
                }
            }

            List<string>values = new List<string>();
            for (var i = 0; i < metadata.Count; i++)
            {

                values.Add(metadata[i].ColumnName);
                values.Add(metadata[i].Type.ToString());
                values.Add("");
                if(tipo=="LOP_MODIFY_ROW")
                    values.Add("");
                ListViewItem lvi = new ListViewItem(values.ToArray());
                listView1.Items.Add(lvi);
                values.Clear();
            }

            AddValues(metadata,table,transid);
        }