コード例 #1
0
        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);
        }
コード例 #2
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();
                }
            }
        }