예제 #1
0
        private void LoadFromFile(IVirtualFile file)
        {
            m_file = file;
            ChangedWinId();
            var doc = new XmlDocument();

            doc.LoadXml(m_file.GetText());
            var root   = doc.DocumentElement;
            var loader = (ITabularDataViewLoader)TabularDataViewLoaderAddonType.Instance.LoadAddon(root.FindElement("Data"));

            m_data = loader.CreateTabularDataView();
            var style = ChartStyle.LoadFromXml(root.FindElement("Style"));

            for (int i = 0; i < lbxStyle.Items.Count; i++)
            {
                if (style.GetType() == lbxStyle.Items[i].Tag.GetType())
                {
                    lbxStyle.Items[i].Tag = style;
                    lbxStyle.SelectOneItem(lbxStyle.Items[i], true);
                    break;
                }
            }

            m_loadProcessor = (IChartDataProcessor)ChartDataProcessorAddonType.Instance.LoadAddon(root.FindElement("Processor"));

            m_modified = false;
        }
예제 #2
0
        public ChartFrame(ITabularDataView data)
        {
            InitializeComponent();
            m_data          = data;
            btnSave.Enabled = SupportsSave;

            InitBegin();
            InitEnd();
        }
예제 #3
0
        public override void GenerateSql(ISqlDumper dmp)
        {
            ITabularDataView tabdata = m_frame.TabularData;

            if (tabdata == null)
            {
                return;
            }
            var props = m_frame.GetDataProperties();
            var sw    = new StringWriter();

            tabdata.GenerateScript(m_script, props, dmp);
        }
예제 #4
0
        internal void GoToReference(ReferenceViewDefinition refdef, BedRow masterRow)
        {
            ITabularDataView newdata = DataStatePer.TableData.TableSource.Database.GetTable(refdef.TableName).GetTabularData();
            int delcnt = m_historyChain.Count - m_historyPosition - 1;

            if (delcnt > 0)
            {
                m_historyChain.RemoveRange(m_historyPosition + 1, delcnt);
            }
            var state = new PerspectiveIndependendState();

            state.TableData           = newdata;
            state.AdditionalCondition = refdef.GetCondition(masterRow);
            m_historyChain.Add(state);
            m_historyPosition++;
        }
예제 #5
0
        protected override void DoLoadData()
        {
            base.DoLoadData();
            ITabularDataView tabdata = null;

            if (m_appobj != null)
            {
                tabdata = m_appobj.GetTabularData(ConnPack);
            }
            if (AsyncTool.IsMainThread)
            {
                tableDataFrame1.TabularData = tabdata;
            }
            else
            {
                tableDataFrame1.Invoke((Action)(() => tableDataFrame1.TabularData = tabdata));
            }
        }
예제 #6
0
        public override ChartData LoadChartData(ITabularDataView data)
        {
            var fmt = new BedValueFormatter(new DataFormatSettings());
            var res = new ChartData();

            res.ValueDefs           = new ChartData.ValueDef[1];
            res.ValueDefs[0]        = new ChartData.ValueDef();
            res.ValueDefs[0].Column = Column;
            res.ValueDefs[0].Label  = Texts.Get("s_count");

            var dct = new Dictionary <string, int>();
            var tbl = data.GetStructure(null);

            int colindex = tbl.Columns.GetNames().IndexOfEx(Column);

            data.LoadAllRows(new TableDataSetProperties(), (row) =>
            {
                row.ReadValue(colindex);
                fmt.ReadFrom(row);
                string curval = fmt.GetText();
                if (!dct.ContainsKey(curval))
                {
                    dct[curval] = 0;
                }
                dct[curval] += 1;
            });

            var pairs = new List <KeyValuePair <string, int> >(dct);

            pairs.SortByKey(p => p.Value);
            pairs.Reverse();
            foreach (var pair in pairs)
            {
                var item = new ChartData.DataItem();
                item.Label  = pair.Key;
                item.Values = new double[] { pair.Value };
                res.Items.Add(item);
            }

            return(res);
        }
예제 #7
0
        public ReferencesTableDataFrame(TableDataFrame masterFrame, ReferenceViewDefinition refdef, BedRow masterRow)
        {
            InitializeComponent();
            //ParentFrame = parentFrame;
            //m_parentFrame = parentFrame;
            MasterFrame = masterFrame;
            m_baseView  = masterFrame.TabularData;
            m_refdef    = refdef;
            m_masterRow = masterRow;
            var src = m_baseView.DatabaseSource.GetTable(m_refdef.TableName);

            State = new TableRelatedState();
            DataStatePer.AdditionalCondition = m_refdef.GetCondition(m_masterRow);
            DataStatePer.TableData           = src.GetTabularData();

            //RefreshCurrentViewNoRedock();
            //MainWindow.Instance.RunInMainWindow(RefreshCurrentViewNoRedock);
            //btnReferences.Enabled = false;
            //TabularData = src.GetTabularDataAndReuse();
            //LoadDependendData();
        }
예제 #8
0
        public override ChartData LoadChartData(ITabularDataView data)
        {
            var fmt = new BedValueFormatter(new DataFormatSettings());
            var res = new ChartData();

            res.ValueDefs = ValueDefs.ToArray();
            var tbl      = data.GetStructure(null);
            var colnames = tbl.Columns.GetNames();
            int labindex = colnames.IndexOfEx(LabelColumn);

            int[] valindexes = new int[ValueDefs.Count];
            for (int i = 0; i < ValueDefs.Count; i++)
            {
                valindexes[i] = colnames.IndexOfEx(ValueDefs[i].Column);
            }

            var pg = new TablePageProperties {
                Count = 128
            };
            var table = data.LoadTableData(pg);

            foreach (var row in table.Rows)
            {
                var item = new ChartData.DataItem();
                row.ReadValue(labindex);
                fmt.ReadFrom(row);
                item.Label  = fmt.GetText();
                item.Values = new double[ValueDefs.Count];
                for (int i = 0; i < ValueDefs.Count; i++)
                {
                    row.ReadValue(valindexes[i]);
                    fmt.ReadFrom(row);
                    Double.TryParse(fmt.GetText(), NumberStyles.Number, CultureInfo.InvariantCulture, out item.Values[i]);
                }
                res.Items.Add(item);
            }
            return(res);
        }
예제 #9
0
        internal void RefreshCurrentView(bool allowChangeDocking)
        {
            if (allowChangeDocking && ParentFrame != null)
            {
                var frm  = ParentFrame;
                var dock = frm.m_dockWrapper;
                frm.ReleaseFrame(this);
                dock.ReplaceContent(this);
            }

            try
            {
                m_programaticallySelectCell = true;

                nbstart.Text = DataState.FirstRecord.ToString();
                nbcount.Text = DataState.RecordCount.ToString();

                if (m_bindedTabularData != TabularData)
                {
                    if (m_bindedTabularData != null)
                    {
                        m_bindedTabularData.LoadedNextData -= OnLoadedNextData;
                    }
                    m_bindedTabularData = TabularData;
                    if (m_bindedTabularData != null)
                    {
                        m_bindedTabularData.LoadedNextData += OnLoadedNextData;
                    }
                }

                m_table = null;

                btnReferences.Enabled  = TabularData != null && TabularData.TableSource != null;
                btnGenerateSql.Enabled = TabularData != null && TabularData.TabDataCaps.Scriptable;

                dataGridView1.DataSource = null;
                tbxFilter.Text           = DataState.Filter ?? "";
                tbxSearch.Text           = DataState.SearchText ?? "";

                if (TabularData != null)
                {
                    SetSettings(TabularData.Settings.TableData(), TabularData.Settings.DataFormat());

                    if (TabularData.Connection != null && TabularData.Connection.Owner == null)
                    {
                        TabularData.Connection.Owner = this;
                    }
                    if (TabularData.Connection != null && !TabularData.Connection.IsOpened)
                    {
                        OpenAndLoadData();
                    }
                    else
                    {
                        LoadDataPage();
                    }
                    cbfilter.Enabled = TabularData.TabDataCaps.Filtering;
                    if (!cbfilter.Enabled)
                    {
                        cbfilter.Checked = false;
                    }
                    cbpaging.Enabled = TabularData.TabDataCaps.Paging;
                    if (!cbpaging.Enabled)
                    {
                        cbpaging.Checked = false;
                    }
                }
                else
                {
                    cbfilter.Enabled = false;
                    cbfilter.Checked = false;
                    cbpaging.Enabled = false;
                }
                if (TabularData != null)
                {
                    lblCurrentTable.Text = TabularData.ToString();
                }
                else
                {
                    lblCurrentTable.Text = "";
                }
            }
            finally
            {
                m_programaticallySelectCell = false;
            }


            if (allowChangeDocking)
            {
                if (DataState.DockPanelFrame != null)
                {
                    m_dockWrapper.ReplaceContent(DataState.DockPanelFrame);
                    DataState.DockPanelFrame.ReuseReleasedFrame(this);
                    MainWindow.Instance.UpdateFrameEnabling(DataState.DockPanelFrame);
                }
                else if (DataState.Perspective != null && DataState.Perspective.DockPanelDesign != null)
                {
                    if (m_dockWrapper != null)
                    {
                        LoadPerspectiveLayout();
                    }
                    else
                    {
                        MainWindow.Instance.RunInMainWindow(LoadPerspectiveLayout);
                    }
                }
            }

            UpdateHistoryEnabling();
        }
예제 #10
0
 public abstract ChartData LoadChartData(ITabularDataView source);
예제 #11
0
 public ContentFrame CreateFrame(ITabularDataView data)
 {
     return(new ChartFrame(data));
 }
예제 #12
0
        //public override string UsageEventName
        //{
        //    get { return "data_browser"; }
        //}

        //public override bool AllowClose()
        //{
        //    if (Detached) return false;
        //    return base.AllowClose();
        //}

        //protected override void DisallowedClose()
        //{
        //    Detached = true;
        //}

        private void LoadDataFromNode()
        {
            bool             loaded     = false;
            var              tabdataobj = m_selectedObject.FindTabularDataObject();
            ITabularDataView data       = null;

            if (tabdataobj != null)
            {
                data = tabdataobj.GetTabularData(ConnPack);
            }
            if (data == null && m_selectedObject != null && m_selectedObject.HasTabularData)
            {
                data = m_selectedObject.GetTabularData();
                if (data != null)
                {
                    data.ChangeConnection(ConnPack);
                }
            }
            if (data != null)
            {
                string key = data.GetConnectionKey();
                try
                {
                    m_currentTableKey = key + "#" + data.TableSource.Database.DatabaseName + "#" + data.TableSource.FullName.ToString() + "#" + data.FixedPerspective;
                }
                catch
                {
                    try
                    {
                        m_currentTableKey = key + "#" + data.TableSource.FullName.ToString() + "#" + data.FixedPerspective;
                    }
                    catch
                    {
                        m_currentTableKey = null;
                    }
                }
                if (m_currentTableKey == null)
                {
                    State = new TableRelatedState();
                }
                else
                {
                    if (m_tablesCache.ContainsKey(m_currentTableKey))
                    {
                        State = m_tablesCache[m_currentTableKey];
                        State.HistoryPosition = 0;
                    }
                    else
                    {
                        State = new TableRelatedState();
                        m_tablesCache[m_currentTableKey] = State;
                    }
                }
                DataStatePer.TableData = data;
                if (data != null && data.FixedPerspective != null)
                {
                    DataStatePer.UseFixedPerspective(data.FixedPerspective);
                }
                RefreshCurrentView();
                loaded = true;
            }

            if (!loaded)
            {
                TabularData = null;
            }
            UpdateHint();
            UpdateCellDataView();
            UpdateState();
        }
예제 #13
0
        public override ChartData LoadChartData(ITabularDataView data)
        {
            var fmt = new BedValueFormatter(new DataFormatSettings());
            var res = new ChartData();

            res.ValueDefs = new ChartData.ValueDef[Items.Count];
            for (int i = 0; i < Items.Count; i++)
            {
                res.ValueDefs[i]        = new ChartData.ValueDef();
                res.ValueDefs[i].Column = Items[i].Column;
                res.ValueDefs[i].Label  = Items[i].Expression + (Items[i].Expression != TimeLineExpression.Count ? " " + Items[i].Column : "");
            }

            var tbl      = data.GetStructure(null);
            var colnames = tbl.Columns.GetNames();

            int[] valindexes = new int[Items.Count];
            for (int i = 0; i < Items.Count; i++)
            {
                valindexes[i] = colnames.IndexOfEx(Items[i].Column);
            }
            int dtcolindex = colnames.IndexOfEx(DateColumn);

            if (dtcolindex < 0)
            {
                return(res);
            }

            var dct = new Dictionary <string, TimeLineGroup>();

            var smallstep = SmallStep;

            if (!UseStructuredTime)
            {
                smallstep = Step;
            }

            // go through all rows
            data.LoadAllRows(new TableDataSetProperties(), (row) =>
            {
                row.ReadValue(dtcolindex);
                fmt.ReadFrom(row);
                string curdt = fmt.GetText();
                string key   = ExtractKey(curdt, Step);
                if (key != null)
                {
                    TimeLineGroup item;
                    if (!dct.ContainsKey(key))
                    {
                        item = new TimeLineGroup {
                            Key = key
                        };
                        dct[key] = item;
                    }
                    else
                    {
                        item = dct[key];
                    }

                    var inkey = ExtractKey(curdt, smallstep);
                    if (inkey != null)
                    {
                        double[] vals;

                        if (!item.Items.ContainsKey(inkey))
                        {
                            vals = new double[Items.Count + 1];
                            for (int i = 0; i < Items.Count; i++)
                            {
                                vals[i] = Double.NaN;
                            }
                            item.Items[inkey] = new ChartData.DataItem {
                                Label = inkey, Values = vals
                            };
                        }
                        else
                        {
                            vals = item.Items[inkey].Values;
                        }
                        vals[Items.Count] += 1; // count
                        for (int i = 0; i < Items.Count; i++)
                        {
                            if (valindexes[i] < 0)
                            {
                                if (Double.IsNaN(vals[i]))
                                {
                                    vals[i] = 0;
                                }
                                vals[i] += 1; // count
                            }
                            else
                            {
                                row.ReadValue(valindexes[i]);
                                fmt.ReadFrom(row);
                                double myval;
                                if (Double.TryParse(fmt.GetText(), NumberStyles.Number, CultureInfo.InvariantCulture, out myval))
                                {
                                    AdaptValue(ref vals[i], myval, Items[i].Expression);
                                }
                            }
                        }
                    }
                }
            });

            // summarize results
            var pairs = new List <KeyValuePair <string, TimeLineGroup> >(dct);

            pairs.SortByKey(p => p.Key);
            foreach (var pair in pairs)
            {
                var item = pair.Value;

                foreach (var itm in item.Items.Values)
                {
                    for (int i = 0; i < Items.Count; i++)
                    {
                        if (Double.IsNaN(itm.Values[i]))
                        {
                            itm.Values[i] = 0;
                        }
                        if (Items[i].Expression == TimeLineExpression.Avg && itm.Values[Items.Count] > 0)
                        {
                            itm.Values[i] /= itm.Values[Items.Count];
                        }
                    }
                }

                if (UseStructuredTime)
                {
                    double[] vals = new double[Items.Count];
                    for (int i = 0; i < Items.Count; i++)
                    {
                        switch (Items[i].TimeSelector)
                        {
                        case TimeGroupSelector.Sum:
                            vals[i] = 0;
                            foreach (var val in item.Items.Values)
                            {
                                vals[i] += val.Values[i];
                            }
                            break;

                        case TimeGroupSelector.Avg:
                            vals[i] = 0;
                            foreach (var val in item.Items.Values)
                            {
                                vals[i] += val.Values[i];
                            }
                            if (item.Items.Count > 0)
                            {
                                vals[i] /= item.Items.Count;
                            }
                            break;

                        case TimeGroupSelector.Min:
                            vals[i] = Double.NaN;
                            foreach (var val in item.Items.Values)
                            {
                                if (Double.IsNaN(vals[i]) || val.Values[i] < vals[i])
                                {
                                    vals[i] = val.Values[i];
                                }
                            }
                            if (Double.IsNaN(vals[i]))
                            {
                                vals[i] = 0;
                            }
                            break;

                        case TimeGroupSelector.Max:
                            vals[i] = Double.NaN;
                            foreach (var val in item.Items.Values)
                            {
                                if (Double.IsNaN(vals[i]) || val.Values[i] > vals[i])
                                {
                                    vals[i] = val.Values[i];
                                }
                            }
                            if (Double.IsNaN(vals[i]))
                            {
                                vals[i] = 0;
                            }
                            break;

                        case TimeGroupSelector.First:
                        {
                            string key = item.Items.Keys.Min();
                            if (key != null)
                            {
                                vals[i] = item.Items[key].Values[i];
                            }
                        }
                        break;

                        case TimeGroupSelector.Last:
                        {
                            string key = item.Items.Keys.Min();
                            if (key != null)
                            {
                                vals[i] = item.Items[key].Values[i];
                            }
                        }
                        break;

                        case TimeGroupSelector.Middle:
                        {
                            var keys = new List <string>(item.Items.Keys);
                            keys.Sort();
                            if (keys.Count > 0)
                            {
                                if (keys.Count % 2 == 1)
                                {
                                    vals[i] = item.Items[keys[keys.Count / 2]].Values[i];
                                }
                                else
                                {
                                    vals[i] = (
                                        item.Items[keys[keys.Count / 2 - 1]].Values[i]
                                        + item.Items[keys[keys.Count / 2]].Values[i]
                                        ) / 2;
                                }
                            }
                        }
                        break;
                        }
                    }
                    res.Items.Add(new ChartData.DataItem {
                        Label = pair.Key, Values = vals
                    });
                }
                else
                {
                    var itm = item.Items.First().Value;
                    res.Items.Add(itm);
                }
            }
            return(res);
        }