Esempio n. 1
0
        private List <string> GetColumnsFromTree(FieldCalculationParser.ParseTreeNode tree)
        {
            List <string> input  = tree.GetHeaderNames();
            List <string> output = new List <string>();

            foreach (string s in input)
            {
                if (!output.Contains(s))
                {
                    output.Add(s);
                }
            }
            return(output);
        }
        private List <PreviewRowItem> getPreviewRowItems()
        {
            List <PreviewRowItem> previewRowItems = new List <PreviewRowItem>();

            //this is where you would get the parse tree from the expressionwindow, and then execute the tree for each row.
            FieldCalculationParser.ParseTreeNode tree = TestWindow.GetTree;
            FieldCalculationParser.ParseTreeNode.Initialize();//clear all errors.

            if (tree != null)
            {
                Database.Reader.SqLiteReader reader = new Database.Reader.SqLiteReader(_filePath, _tableName);
                object[]      row;
                List <string> usedheaders   = tree.GetHeaderNames();
                string[]      uniqueheaders = getUniqueHeaders(usedheaders);
                tree.SetColNums(uniqueheaders.ToList());
                Int64      count        = reader.RowCount();
                List <int> selectedRows = null;

                List <object> output = new List <object>();

                reader.Open();
                object[] original    = reader.Column(_columnName);
                object[] primaryKeys = reader.Column(_selectionColumnName);
                //needs to operate on selected rows or not.
                //ifselected rows, update the entire column, but put the original value in for non selected rows.
                if (UseSelection)
                {
                    selectedRows = new List <int>();
                    object[] tmp = reader.Column(_selectionColumnName);
                    foreach (long uid in _selectedKeys)
                    {
                        selectedRows.Add(Array.IndexOf(tmp, uid));
                    }
                }

                for (int i = 0; i < count; i++)
                {
                    if (!UseSelection || selectedRows.Contains(i))
                    {
                        FieldCalculationParser.ParseTreeNode.RowOrCellNum = (int)i;//whatever.
                        if (uniqueheaders.Count() > 0)
                        {
                            row = reader.Row((int)i, uniqueheaders);
                            tree.Update(ref row);
                        }
                        output.Add(tree.Evaluate().GetResult);
                    }
                    else
                    {
                        output.Add(original[i]);
                    }

                    previewRowItems.Add(new PreviewRowItem(primaryKeys[i], original[i], output[i]));
                }

                reader.Close();
            }

            if (tree.GetComputeErrors.Count > 1)
            {
                //do not write to file.
                StringBuilder s = new StringBuilder();
                foreach (string o in tree.GetComputeErrors)
                {
                    s.AppendLine(o);
                }
                ErrorWindow err = new ErrorWindow(s.ToString());
                err.Title = "Output";
                err.ShowDialog();
            }

            return(previewRowItems);
        }
Esempio n. 3
0
 public void Parse()
 {
     if (_FirstRowOfData == null)
     {
         _Result = "No Rows In Database";//doesnt work with mvvm very well..
         //raiseevent parsesuccess
         return;
     }
     _ParenColors = new Stack <System.Windows.Media.SolidColorBrush>();
     _TextBlock.Inlines.Clear();
     if (_Numlines != base.LineCount)
     {
         ShiftDownward();
     }
     _s.Restart();
     if (!_BW.IsBusy)
     {
         _BW.RunWorkerAsync();
     }
     byte[] strbytes = new System.Text.UTF8Encoding().GetBytes(base.Text);
     System.IO.MemoryStream         ms      = new System.IO.MemoryStream(strbytes);
     FieldCalculationParser.Scanner scanner = new FieldCalculationParser.Scanner(ms);
     FieldCalculationParser.Parser  parser  = new FieldCalculationParser.Parser(scanner);
     parser.TokenFound += SetRichText;
     FieldCalculationParser.ParseTreeNode.IsCaseSensitive = _IsCaseSensitive;
     FieldCalculationParser.ParseTreeNode.RowOrCellNum    = 0;
     try
     {
         _tree = parser.Parse(_headers, _HeaderTypes, _OutputType);
         _TextBlock.Inlines.Add(" ");//why?
         if (_tree == null)
         {
             _Result = "";
             ErrorsFound(true);
         }
         else
         {
             if (_tree.GetParseErrors.Count() > 0)
             {
                 if (_tree.ContainsError())
                 {
                     _Result = "Tree Contains Parse Errors";
                     ErrorsFound(false);
                 }
                 else
                 {
                     _Result = "Invalid Syntax, Check Error Log";
                     ErrorsFound(false);
                 }
             }
             else
             {
                 if (_tree.containsVariable())
                 {
                     List <string> selectedheaders = GetColumnsFromTree(_tree);
                     if (selectedheaders.Count() != 0)
                     {
                         _tree.SetColNums(selectedheaders);
                         object[] selectedvalues = GetDataFromDatabaseForUniqueColumns(selectedheaders);
                         _tree.Update(ref selectedvalues);
                     }
                 }
                 _Result = _tree.Evaluate().GetResult.ToString();
                 ParseSuccess();
             }
         }
     }
     catch (Exception ex)
     {
         _Result = "Exception";
         ErrorsFound(true);
     }
 }
Esempio n. 4
0
        private void CmdExecute_Click(object sender, RoutedEventArgs e)
        {
            //this is where you would get the parse tree from the expressionwindow, and then execute the tree for each row.
            FieldCalculationParser.ParseTreeNode tree = TestWindow.GetTree;
            FieldCalculationParser.ParseTreeNode.Initialize();//clear all errors.

            if (tree != null)
            {
                Database.Reader.SqLiteReader reader = new Database.Reader.SqLiteReader(_filePath, _tableName);
                object[]      row;
                List <string> usedheaders   = tree.GetHeaderNames();         //will include duplicates
                string[]      uniqueheaders = getUniqueHeaders(usedheaders); //removes duplicates
                tree.SetColNums(uniqueheaders.ToList());                     //lets the tree know what index in the array of object to look for for each header.
                Int64 count = reader.RowCount();

                List <long> output = new List <long>();

                reader.Open();
                //needs to operate on selected rows or not.

                //ifselected rows, only iterate on the current selection.
                if (UseSelection)
                {
                    object[] tmp = reader.Column(_selectionColumnName);

                    List <int> items = new List <int>();
                    int        idx   = 0;
                    foreach (long uid in _selectedKeys)
                    {
                        idx = Array.IndexOf(tmp, uid);
                        FieldCalculationParser.ParseTreeNode.RowOrCellNum = idx;
                        if (uniqueheaders.Count() > 0)
                        {
                            row = reader.Row(idx, uniqueheaders);
                            tree.Update(ref row);
                        }
                        if ((bool)tree.Evaluate().GetResult)
                        {
                            //select it!
                            output.Add(uid);
                        }
                    }
                }
                else
                {
                    object[] uniqueIDS = reader.Column(_selectionColumnName);
                    for (Int64 i = 0; i < count; i++)
                    {
                        FieldCalculationParser.ParseTreeNode.RowOrCellNum = (int)i;//whatever.
                        if (uniqueheaders.Count() > 0)
                        {
                            row = reader.Row((int)i, uniqueheaders);
                            tree.Update(ref row);
                        }
                        if ((bool)tree.Evaluate().GetResult)
                        {
                            //select it!
                            output.Add((long)uniqueIDS[i]);
                        }
                    }
                }

                reader.Close();
                if (tree.GetComputeErrors.Count > 1)
                {
                    //do not update selection
                    StringBuilder s = new StringBuilder();
                    foreach (string o in tree.GetComputeErrors)
                    {
                        s.AppendLine(o);
                    }
                    ErrorWindow err = new ErrorWindow(s.ToString());
                    err.Title = "Output";
                    err.ShowDialog();
                }
                else
                {
                    //update _selectedKeys;
                    SelectedKeys = output;
                    //raise event?
                    FilterWasSuccessful = true;
                    Close();
                }
            }
        }