private void FormatDataGridView()
        {
            this.dataGrid1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            if (dataGrid1.ColumnCount > 0)
            {
                this.dataGrid1.Columns[0].ReadOnly = true;
            }

            for (int c = 1; c < dataGrid1.ColumnCount; c++)
            {
                dataGrid1.Columns[c].DefaultCellStyle.Format    = msDataTable.LookupSeries(c).DisplayFormat;
                dataGrid1.Columns[c].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
                dataGrid1.Columns[c].ReadOnly = msDataTable.LookupSeries(c).ReadOnly;
            }
        }
        /// <summary>
        /// Recompute selected points
        /// Required: selected point must have calculation
        /// </summary>
        public void Undo()
        {
            DataGridViewSelectedCellCollection x = timeSeriesSpreadsheet1.GetSelectedCells();

            try
            {
                foreach (DataGridViewCell cell in x)
                {
                    if (cell.ColumnIndex != 0) // not date column
                    {
                        DataRow row = ((DataRowView)cell.OwningRow.DataBoundItem).Row;
                        MultipleSeriesDataTable tbl = row.Table as MultipleSeriesDataTable;
                        DateTime t        = Convert.ToDateTime(row[0]);
                        string   interval = tbl.TableName;
                        HdbPoet.TimeSeriesDataSet.SeriesRow s = tbl.LookupSeries(cell.ColumnIndex);
                        if (s.IsComputed)
                        {
                            Hdb.Instance.Calculate_Series(s.hdb_site_datatype_id, interval, t, dataSet.GraphRow.TimeZone);
                        }
                        else
                        {
                            Logger.WriteLine("Warning series is not computed " + s.SiteName + " " + s.hdb_site_datatype_id);
                        }
                    }
                }
            }
            catch (OracleException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        public void SetFlagForSelectedCells(bool overwrite)
        {
            //    List<string> msgList = new List<string>();
            string msg = "Overwrite Flag will be set for all selected cells";

            if (!overwrite)
            {
                msg = "Overwrite Flag will be cleared for all selected cells";
            }


            if (MessageBox.Show(msg, "Confirm Setting of Overwrite Flag", MessageBoxButtons.OKCancel) != DialogResult.OK)
            {
                return;
            }

            DataGridViewSelectedCellCollection x = timeSeriesSpreadsheet1.GetSelectedCells();

            try
            {
                foreach (DataGridViewCell cell in x)
                {
                    if (cell.ColumnIndex != 0) // no date column
                    {
                        DataRow row = ((DataRowView)cell.OwningRow.DataBoundItem).Row;
                        MultipleSeriesDataTable tbl = row.Table as MultipleSeriesDataTable;
                        DateTime t        = Convert.ToDateTime(row[0]);
                        string   interval = tbl.TableName;
                        HdbPoet.TimeSeriesDataSet.SeriesRow s = tbl.LookupSeries(cell.ColumnIndex);

                        Hdb.Instance.SetOverwriteFlag(s.hdb_site_datatype_id, interval, t, overwrite, dataSet.GraphRow.TimeZone);
                    }
                }
            }
            catch (OracleException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void menuDetails_Click(object sender, EventArgs e)
        {
            DataGridViewCell cell = dataGrid1.SelectedCells[0];

            if (cell.ColumnIndex != 0 && cell.Value != DBNull.Value)
            {
                DataRow row = ((DataRowView)cell.OwningRow.DataBoundItem).Row;
                MultipleSeriesDataTable tbl = row.Table as MultipleSeriesDataTable;
                DateTime t        = Convert.ToDateTime(row[0]);
                string   interval = tbl.TableName;
                HdbPoet.TimeSeriesDataSet.SeriesRow s = tbl.LookupSeries(cell.ColumnIndex);
                var info = Hdb.Instance.BaseInfo(t, s.hdb_site_datatype_id, interval);

                info = DataTableUtility.Transpose(info);
                TableViewer tv = new TableViewer(info);
                tv.Show();


                //msDataTable
                //row[cell.ColumnIndex] = DBNull.Value;
            }
        }
        internal void SetValidationFlagForSelectedCells(string flag)
        {
            string msg = "Validation flag will be set to '" + flag + "'  for all selected cells";

            if (flag.Trim() == "")
            {
                msg = "Validation flag will be set to 'null' (cleared)  for all selected cells";
            }

            if (MessageBox.Show(msg, "Confirm Setting of Validation Flag", MessageBoxButtons.OKCancel) != DialogResult.OK)
            {
                return;
            }


            DataGridViewSelectedCellCollection x = timeSeriesSpreadsheet1.GetSelectedCells();

            try
            {
                foreach (DataGridViewCell cell in x)
                {
                    if (cell.ColumnIndex != 0) // no date column
                    {
                        DataRow row = ((DataRowView)cell.OwningRow.DataBoundItem).Row;
                        MultipleSeriesDataTable tbl = row.Table as MultipleSeriesDataTable;
                        DateTime t        = Convert.ToDateTime(row[0]);
                        string   interval = tbl.TableName;
                        HdbPoet.TimeSeriesDataSet.SeriesRow s = tbl.LookupSeries(cell.ColumnIndex);
                        Hdb.Instance.SetValidationFlag(s.hdb_site_datatype_id, interval, t, flag, dataSet.GraphRow.TimeZone);
                    }
                }
            }
            catch (OracleException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }