private void ctxtMnuItemFilter_Click(object sender, EventArgs e)
        {
            var mclsSelected = (clsDatasetTreeNode)ctltreeView.SelectedNode.Tag;

            if (ctltabPage == null || mclsSelected == null || mclsSelected.mDTable == null)
            {
                MessageBox.Show("Data not loaded", "Nothing to do");
                return;
            }

            var selectedRowData = new StringBuilder();
            selectedRowData.Append("c(");

            var currGrid = ((ucDataGridView)this.ctltabPage.Controls[0]).TableGrid;
            var selectedRows = currGrid.SelectedRows;

            if (selectedRows.Count < 2)
            {
                MessageBox.Show("At least two rows of data must be selected in order to filter using Row IDs", "Not enough rows");
                return;
            }

            var addComma = false;
            foreach (DataGridViewRow row in selectedRows)
            {
                if (addComma)
                    selectedRowData.Append(",");

                selectedRowData.Append(@"""" + row.Cells[0].Value + @"""");
                addComma = true;
            }
            selectedRowData.Append(")");

            var mfrmRowFilter = new frmFilterBasedOnRowIDs
            {
                PopulateDataComboBox = AvailableDataSources()
            };

            if (mfrmRowFilter.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            var datasetNameInR = (mhtDatasets[mfrmRowFilter.Dataset]).mstrRdatasetName;

            mintFilterTblNum++;
            var filtTableName = "filteredData" + mintFilterTblNum;
            var rcmd = filtTableName + "<- filterOnRowIds(" + datasetNameInR + "," + selectedRowData + ")";
            try
            {
                mRConnector.EvaluateNoReturn(rcmd);
                if (mRConnector.GetTableFromRmatrix(filtTableName))
                {
                    var mDTfiltered = mRConnector.DataTable.Copy();

                    mDTfiltered.TableName = filtTableName;
                    mDTfiltered.Columns[0].ColumnName = "ID";
                    AddDataset2HashTable(mDTfiltered);
                    if (mhtDatasets.ContainsKey("Filtered Data" + mintFilterTblNum.ToString()))
                        AddDataNode(mhtDatasets["Filtered Data" + mintFilterTblNum.ToString()]);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Exemplo n.º 2
0
        private void ctxtMnuItemFilter_Click(object sender, EventArgs e)
        {
            var mclsSelected = (clsDatasetTreeNode)ctltreeView.SelectedNode.Tag;

            if (ctltabPage == null || mclsSelected == null || mclsSelected.mDTable == null)
            {
                MessageBox.Show("Data not loaded", "Nothing to do");
                return;
            }

            var selectedRowData = new StringBuilder();

            selectedRowData.Append("c(");

            var currGrid     = ((ucDataGridView)this.ctltabPage.Controls[0]).TableGrid;
            var selectedRows = currGrid.SelectedRows;

            if (selectedRows.Count < 2)
            {
                MessageBox.Show("At least two rows of data must be selected in order to filter using Row IDs", "Not enough rows");
                return;
            }

            var addComma = false;

            foreach (DataGridViewRow row in selectedRows)
            {
                if (addComma)
                {
                    selectedRowData.Append(",");
                }

                selectedRowData.Append(@"""" + row.Cells[0].Value + @"""");
                addComma = true;
            }
            selectedRowData.Append(")");

            var mfrmRowFilter = new frmFilterBasedOnRowIDs
            {
                PopulateDataComboBox = AvailableDataSources()
            };

            if (mfrmRowFilter.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            var datasetNameInR = (mhtDatasets[mfrmRowFilter.Dataset]).mstrRdatasetName;

            mintFilterTblNum++;
            var filtTableName = "filteredData" + mintFilterTblNum;
            var rcmd          = filtTableName + "<- filterOnRowIds(" + datasetNameInR + "," + selectedRowData + ")";

            try
            {
                mRConnector.EvaluateNoReturn(rcmd);
                if (mRConnector.GetTableFromRmatrix(filtTableName))
                {
                    var mDTfiltered = mRConnector.DataTable.Copy();

                    mDTfiltered.TableName             = filtTableName;
                    mDTfiltered.Columns[0].ColumnName = "ID";
                    AddDataset2HashTable(mDTfiltered);
                    if (mhtDatasets.ContainsKey("Filtered Data" + mintFilterTblNum.ToString()))
                    {
                        AddDataNode(mhtDatasets["Filtered Data" + mintFilterTblNum.ToString()]);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }